Subscribe to RSS

How To: Delete Duplicate Posts in WordPress

How To: Delete Duplicate Posts in WordPress

A common problem often encountered is the creation of duplicate posts in WordPress. This usually happens as soon as you start using automation plugins and/or feeds content to your blog via RSS.

This common problem is encountered often, and there is a plugin available to fix this : Auto Delete Duplicate Post, but it is set to run every time you publish a new post, so this will put some pressure on your blog.

You can also do it manually via MySQL:

DELETE bad_rows.*
from wp_posts as bad_rows
inner join (
select post_title, MIN(id) as min_id
from wp_posts
group by post_title
having count(*) > 1
) as good_rows on good_rows.post_title = bad_rows.post_title
and good_rows.min_id <> bad_rows.id

Note: Above example is when you have “wp_” as your table name prefix.

The above code is provided by comments from the WordPress Support Forum, as well as from Kieran Barnes – WordPress WP-O-Matic Duplicate Posts Fix.

Finally, I have just sent in an approval for WordPress to host a plugin which will help you do this, by adding another tool to your WordPress arsenal. The plugin will be free of charge. I will make an announcement when the plugin is released.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

4 Comments

  1. thanks buddy. ive been looking for a way to clean up my WordPress posts. plugin works great

  2. Thanks for this tip. It really works and helped me a lot. I am curious about one thing though. What happens to the custom fields of those duplicate posts? Is there a way to delete those too?

    My scenario is that I am using simple pie to pull RSS. For each feed pulled, a couple of custom fields are also created along with the post. I can delete the duplicate posts using the script you have provided but not sure how to take care of the custom fields of those duplicating posts. Can you please shed some light on this too?

    Thanks

    • Hi Mudasser

      This feature is not built into DDP, but the orphaned post meta tags problem along with other database cluttering concerns can be handled by my other plugin, WP Caretaker.

      Here is the full list of features:

      post drafts (unpublished posts),post revisions (old versions of posts), spam comments, unapproved comments, pingbacks, trackbacks, unused tags, tags used for only a single post, tags used to link only two posts and also optimize the database tables.

      Read more here:

      WP Caretaker for WordPress

  3. Any idea how to use a mySQL query to delete duplicate posts but only in identical categories? For example I have 200k posts, many have the same post title but are in separate categories, they should not be deleted. Just posts with the same title and in the same category. Thanks.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

PRIVACY POLICY: Your privacy is important to us. We will never sell or rent your email address and you can unsubscribe at any time.