What are unused postmeta?
Each post in WordPress can store metadata in the wp_postmeta table. These metadata entries contain extra information such as SEO settings, layout preferences, or plugin data. Over time, when plugins or themes are removed or stop using certain meta keys, they leave behind unused postmeta entries that no longer serve any purpose.
How they affect your database?
Unused postmeta entries remain stored in the wp_postmeta table even though they are no longer connected to any active functionality. This unnecessary data bloats your database, increases backup size, and can slow down post queries and overall site performance, especially on large installations.
How to clean them?
1. Using Advanced Database Cleaner plugin
You can safely remove unused postmeta entries using the General Cleanup module in Advanced Database Cleaner plugin.
The plugin intelligently identifies postmeta that are not linked to any existing post or are related to removed plugins or themes. You can also:
- Delete all unused postmeta entries with one click.
- Schedule automatic cleanups for continuous optimization.
2. Using a raw SQL query
If you prefer a manual cleanup, you can use this SQL command in phpMyAdmin for example:
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
For multisite setups, this query must be run for each subsite, replacing wp_ with the appropriate prefix (for example, wp_2_, wp_3_, etc.).
Note:
While you can manually run these SQL commands to clean unused postmeta, we strongly recommend using the Advanced Database Cleaner plugin.
It uses WordPress’s internal cleaning methods, automatically handles multisite installations, and ensures that all related data is safely removed while keeping your database consistent and stable.