What are duplicated postmeta?
Each post in WordPress can have metadata, known as postmeta, which stores additional information such as SEO data, custom fields, or plugin-related settings. Duplicated postmeta entries occur when multiple rows in the wp_postmeta table have the same meta_key and post_id. These duplicates often result from poorly coded plugins or repeated saves and can unnecessarily inflate your database size.
How they affect your database?
Duplicated entries in the wp_postmeta table waste storage space and can slow down database queries, especially on websites with thousands of posts. They also increase backup sizes and may lead to inconsistent behavior if multiple entries for the same key exist.
How to clean them?
1. Using Advanced Database Cleaner plugin
You can safely remove duplicated postmeta entries using the General Cleanup module in Advanced Database Cleaner plugin.
This method is safe, smart, and fully automated. You can configure it to:
- Identify and delete all duplicated postmeta records.
- Schedule automatic cleanups to ensure your database stays optimized over time.
2. Using a raw SQL query
If you prefer to clean manually, you can use this SQL command in phpMyAdmin for example:
DELETE pm1 FROM wp_postmeta pm1
INNER JOIN wp_postmeta pm2
WHERE
pm1.meta_id > pm2.meta_id
AND pm1.post_id = pm2.post_id
AND pm1.meta_key = pm2.meta_key;
In multisite environments, execute the query for each subsite, replacing wp_ with the subsite’s table prefix (for example, wp_2_, wp_3_, etc.).
Note:
While you can manually run these SQL commands to clean 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.