Wordpress WP-O-Matic Duplicate Posts Fix

July 5th, 2008
No Gravatar

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! ***

Direct Download

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.

5 Responses to “Wordpress WP-O-Matic Duplicate Posts Fix”

  1. SaschaNo Gravatar Says:

    Excellent, Thanks!
    Very nice script, perfect work-around until a new wp-o-matic release will have fixed this annoying bug hopefully :-)

  2. raTNo Gravatar Says:

    Thanks!
    I was Looking for it

  3. WP-O-Matic Bug Fixes Round Up | kieran barnes | kieranbarnes Says:

    [...] Wordpress WP-O-Matic Duplicate Posts Fix [...]

  4. SidNo Gravatar Says:

    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….

  5. TonyNo Gravatar Says:

    Very, very, very good plugin safelife safetime safeall…

    thank you so much

Leave a Reply