Created
October 4, 2012 19:31
-
-
Save cyberhobo/3835864 to your computer and use it in GitHub Desktop.
Sometimes post imports in WordPress can create duplicate custom fields for posts that already exist. This will delete custom fields on posts the have the same key and value. A post type restriction is included as an example of further narrowing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE o | |
/* SELECT p.post_title, o.*, pmi.* */ | |
FROM wp_postmeta AS o | |
INNER JOIN wp_posts AS p ON p.ID = o.post_id | |
INNER JOIN wp_postmeta AS pmi ON pmi.post_id = o.post_id AND pmi.meta_key = o.meta_key AND pmi.meta_value = o.meta_value | |
WHERE p.post_type = 'post' | |
AND pmi.meta_id < o.meta_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment