0

I came across this plugin "Fix Duplicates" which is able to find duplicate posts based on post title and by replacing value from "post_title" to "post_content" in a few places i am able to make this plugin find posts by duplicate content.

Code for the Plugin http://snippi.com/s/yw9ztfu

Now i want to find posts by duplicate featured images and to be honest i have no clue how to do that, can someone please tell me or if possible make changes to the code for this plugin so that it is able to find posts by duplicate featured images?

Kind Regards
Micheal C.

1

The featured image's ID is saved in a post meta field by the name of _thumbnail_id, so with a little bit of joining, you can use MySQL to search them for you:

SELECT p1.ID as ID1, p2.ID AS ID2 FROM
wp_posts p1 LEFT JOIN wp_postmeta pm1 ON (p1.ID = pm1.post_id AND pm1.meta_key = '_thumbnail_id'),
wp_posts p2 LEFT JOIN wp_postmeta pm2 ON (p2.ID = pm2.post_id AND pm2.meta_key = '_thumbnail_id')
WHERE
p1.post_type = p2.post_type AND
p1.ID < p2.ID AND
pm1.meta_value = pm2.meta_value AND
pm1.meta_value IS NOT NULL;

This looks for shared featured images within the same post_type, you can just remove that condition if you want to look across all post types. p1.ID < p2.ID is in there so we don't get repeated reports (e.g. "1, 2" and "2, 1"), and it makes sure that we don't compare a post with itself.

| improve this answer | |
  • Awesome! thanks for that. btw i am really sorry but i am total noob when it comes to coding, if possible can you please edit the part of this link code so that this plugin is able to exactly what you said above, i tried to do it myself but its showing syntax error :P i would really appreciate if you could, this would really help me a lot. Thanks once again for the reply. – Micheal Calone Dec 27 '17 at 14:36
  • There are multiple parts in that plugin that deal with duplicates, which are you trying to adapt? – janh Dec 27 '17 at 14:55
  • Can you replace all if possible? I think one part deals with finding, other one lists the posts and last one deletes the duplicates right? – Micheal Calone Dec 27 '17 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.