WordPress WP-O-Matic Duplicate Posts Fix
Posted on July 5, 2008
Got a problem with WP-O-Matic creating duplicate posts? Or just WordPress in general. Me too.
I wrote a script to run on a regular basis so sort this problem out.Create wp-posts-cleanup.php in your wordpress/wp-config/plugins/ directory,
<?php
require_once(dirname(__FILE__) . '/../../wp-config.php');
require_once(dirname(__FILE__) . '/../../wp-includes/wp-db.php');
$wpdb->show_errors();
$dupes = $wpdb->get_results('select 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;
');
foreach ($dupes as $dupe) {
echo $dupe->post_title ."\n";
}
$wpdb->query('
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;
');
?>
Running this will search and delete all your duplicate posts based on the post_title column.
*** Careful, it will delete the posts as soon as it runs! ***
Related posts
- WP-O-Matic Bug Fixes Round Up
I've run into quite a few issues in the latest 1.0RC3-7 release of WP-O-Matic. Here's... - Strictly Auto Tags Plugin & Custom Posts
The Strictly Auto Tags plugin for WordPress does a fantastic job at automatically tagging content so... - How to move WordPress directory or server – properly
I ran into an annoying, but easily avoided problem the other day. When moving a... - WP-o-Matic fix for WordPress 2.5
WP-o-Matic makes autoblogging a easy by automatically creating posts from the RSS/Atom feeds you give... - WP-o-Matic Upgrade Fix
So I rolled out some WP-o-Matic upgrades recently. I was all excited that version 1.0RC3-7...




August 21st, 2008 - 16:17
Excellent, Thanks!
Very nice script, perfect work-around until a new wp-o-matic release will have fixed this annoying bug hopefully
September 11th, 2008 - 13:15
Thanks!
I was Looking for it
October 14th, 2008 - 01:53
For some odd reason, I just can’t figure out how to add this plug in to my directory – SOMEBODY HELP!!!!
My email address = sid1 [at] gmx (dot) com
Thanks….
November 10th, 2008 - 23:57
Very, very, very good plugin safelife safetime safeall…
thank you so much
January 15th, 2009 - 18:31
Hi Kiernan,
I seem to be having the same problem as Sid.
I cannot seem to figure out how to incoporate the fix. I see that I have to put a file in /wp-config/plugins/ directory but the only directories I see in my files are wp-admin,wp-content, and wp-includes.
Any help you can share will be greatly appreciated.
Thanks:), I sent you a direct email also
January 30th, 2009 - 04:21
I am using wordpress 2.7 with WP o-matic 1.0RC4-6. I don’t have wordpress/wp-config/plugins/ directory, so I created it in wordpress/wp-content/plugins/ directory but it din’t appear in the installed plugin area. How shall I activate and run the script? Can someone pls help?
March 3rd, 2009 - 07:12
wow!!!!
))) thank you
March 6th, 2009 - 21:57
Many thanks for this fix. It doesn’t actually install as a plug-in but runs fine from browser, many thanks again, great work.
March 31st, 2009 - 21:08
Will this work on the latest WP version?
I’m a little bit hesitant to try it if it messes up my site…
April 1st, 2009 - 15:20
Works great!!!
FYI – You dont need to go to the plugins page in admin to use this. Just access the url where it’s located:
http://bloke.org/wp-content/plugins/wp-o-matic-cleanup.php
Thanks for the great script. Could you add the feature to prevent duplicate posts from being published?
April 3rd, 2009 - 17:36
I added this to wp-content/plugins. How do i run it?
April 22nd, 2009 - 20:21
Be sure to check first if your db has wp_posts and not wp_123_posts.
Check the prefix of the config file.
April 28th, 2009 - 10:30
What this tools is auto run and delete duplicate content after upload to wp-content/plugins/ ?
June 9th, 2009 - 10:31
Nice work! Saved a big days work.
June 10th, 2009 - 07:03
Nice! Thanks a lot.
July 16th, 2009 - 12:20
Hi there mate, I was using basically the same query within phpMyAdmin:
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
Now one question: how would you modify the query to select only duplicated records on a given category?
The following query selects all records from a given category:
SELECT * FROM wp_posts
LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE
(wp_term_taxonomy.term_id = 27)
AND wp_term_taxonomy.taxonomy = 'category'
How would you adjust that? Maybe with a nested query? Or?
Thanks
July 20th, 2009 - 12:34
hello Keiran, first I wanna thanks for you nice plugin,i really save me many times, but since there’s WP 2.81 this plugin seems doesn’t work anymore. I think its because WP 2.8 has changes some db table structure ?
July 20th, 2009 - 12:36
hello Keiran, first I wanna thanks for you nice plugin,it really save me many times, but since there’s WP 2.81 this plugin seems doesn’t work anymore. I think its because WP 2.8 has changes some db table structure ?
July 29th, 2009 - 20:05
Hey there and thanks for the plugin. Will this fix the problem where the suffix -2 is added to dupe posts?
In other words. Usualy wp-o-matic will have a post called:
http://blog.com/New-template/
http://blog.com/New-template-2/
http://blog.com/New-template-3/
Will this tool remove the 2 posts with the suffix -2 and -3?
September 23rd, 2009 - 14:18
Does this work on the latest version of WordPress? 2.8.4 I think.
October 10th, 2009 - 01:21
Ok, so if I have a prefix of say wp_pre in my database file would I have to change every instance of wp_posts to wp_pre_posts for it to run correctly?
October 15th, 2009 - 21:13
Ok. I saved this script in a .php file, placed it within the plugins directory, allowed 777 mod file permissions and it won’t work. Any advice?
October 15th, 2009 - 21:48
ok so i swapped out the wp_posts in the code provided and inserted wp_pre_posts since my prefix is wp_pre and ran the code..all it does is render the page as displaying just the text and not as a php program. i saved it as a php program…and uploaded it to the plugins directory.
still no luck.
suggestions?
February 7th, 2010 - 18:24
wow great script thanks for this works really great . i was using delete duplicate posts plugin , it was working fine before but it just freeze when there are near thousands posts and wp o matic creating lot of duplicate posts like 5-6 time of each post. Now no problem at all this takes a sec to do it. save lot of work Thanks again
February 10th, 2010 - 13:54
not working
February 16th, 2011 - 18:47
I’m on 3.0.5 and still the same problem from wp_insert_post.
I didn’t take your solution, but it inspired me to delete duplicate posts, so thank you
July 8th, 2011 - 16:14
how do i run this automatically?? this is nice plugin.. very well work done
July 8th, 2011 - 16:38
With a cron!
July 12th, 2011 - 08:51
for me unfortunately it’s not working ( way too large db at the moment I think ) … around 35K posts , with I think more than 5K duplicates maybe more … I try to run it from one vps on dreamhost and wasn’t working ( with max memory allowed ) …
July 12th, 2011 - 09:54
I think you’d have to write a small wrapper round it to split the results into chunks. Like a LIMIT 1000 on your SQL query.
September 14th, 2011 - 08:01
That was a wonderful code. Thank you very much. 18000 posts in data vase and it was quick and efficient…
Kyle