delete duplicates wp_postmeta

I'm looking to cleanup wp_postmeta. I've found dozens of duplicate entries.

I've spend about 8 hours looking through topics and trying code and plugins to no avail.

The most useful article on the subject I found is this.

However the article is from 5 years ago and I'm not sure that the suggested code leaves at least 1 entry from each duplicate. Also the plugin that is suggested (Cleanup Duplicate Meta) is exactly what I need, but it hasn't been updated for 7 years. The plugin tells me there are over a million duplicates, but when I click to clean it up, nothing happens.

Can someone confirm that

DELETE FROM `wp_postmeta` WHERE `meta_id` NOT IN (SELECT * FROM (SELECT MAX(`pm`.`meta_id`) FROM `wp_postmeta` pm GROUP BY `pm`.`post_id`, `pm`.`meta_key`) x)

will delete the duplicates but leave at least 1 entry of each?

Topic duplicates post-meta Wordpress

Category Web


This should do it:

DELETE t1 FROM wp_postmeta t1, wp_postmeta t2 
WHERE t1.meta_id > t2.meta_id 
AND t1.meta_key = t2.meta_key 
AND t1.post_id = t2.post_id

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.