Wordpress WP-O-Matic Duplicate Posts Fix
July 5th, 2008Got 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! ***
| Bookmark it del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Propeller | Yahoo |
Was this post useful to you? Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the PHP, Wordpress category.
August 21st, 2008 at 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 at 13:15
Thanks!
I was Looking for it
October 1st, 2008 at 16:57
[...] Wordpress WP-O-Matic Duplicate Posts Fix [...]
October 14th, 2008 at 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 at 23:57
Very, very, very good plugin safelife safetime safeall…
thank you so much