I would like to add the capability to the following code so that it also deletes posts that have the same meta key value. In other words, there is a meta key 'source_link' and I would like to delete duplicates that have the same value for 'source_link'. This is the current code:
$wpdb->query("
DELETE double_posts.*
FROM $wpdb->posts as double_posts
INNER JOIN (
SELECT post_title, MIN(id) as min_id
FROM $wpdb->posts
WHERE (post_status = 'publish'
AND post_type = 'post')
OR (post_status = 'published'
AND post_type = 'post')
GROUP BY post_title
HAVING COUNT(*) > 1
) AS orig_posts ON orig_posts.post_title = double_posts.post_title
AND orig_posts.min_id <> double_posts.id
");
Currently it jsut deletes posts with duplicate post titles. I would like to keep that, then add the deleting by duplicate meta key value. Any help here would be great! Thanks.