Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created November 13, 2013 00:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/7441174 to your computer and use it in GitHub Desktop.
Save mustafauysal/7441174 to your computer and use it in GitHub Desktop.
Bulk Fixing WordPress Duplicated Posts! Read for more information: http://uysalmustafa.com/2013/11/13/bulk-fixing-wordpress-duplicated-posts/
<?php
require( 'wp-load.php' );
//set_time_limit(30000); // you can set time limit, but I prefer to use command line > php fix-duplicated-posts.php
$query = "SELECT id,post_name, Count(*) FROM wp_posts WHERE post_type = 'post' GROUP BY post_name HAVING Count(*) > 1";
$duplicated_posts = $wpdb->get_results( $query );
foreach ( $duplicated_posts as $result ) {
$prepost = get_post($result->id);
$prepost->post_name = '';
wp_update_post( $prepost );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment