I just exported a largish WP blog from MediaTemple to PHPFog.

I used the standard WordPress export and import plugins.

For some unknown reason all of my media assets have been duplicated. I now have twice as many images per post.

If an original file was called “Lot-44-Warrens.jpg” it now has a duplicate called “Lot-44-Warrens1.jpg” Both files are attached to the same post.

I now have many duplicate images across about 250+ posts.

So my question is how do I remove said duplicates from the media library and from the posts?

I tried to search the media library with “*1.jpg”, but it didn’t work.

Looking for a neat solution that doesn’t mean removing each dupe manually.

Perhaps there is a MySQL query I can run to remove the dupes from the library and the posts?

The site in question is: http://igrealty.phpfogapp.com/ .

4 s
4

combining the two answer on this page, I found this worked.

$args = new WP_Query(array(
  'post_type' => 'post',
  'posts_per_page' => -1
));

$loop = new WP_Query($args);

while($loop->have_posts()) {
  the_post();
  $args2 = array(
    'order' => 'ASC',
    'post_type' => 'attachment',
    'post_parent' => $post->ID,
    'post_mime_type' => 'image');
    $attachments = get_posts($args2);
    if($attachments) {
      foreach ($attachments as $img_post) {
        if( ((strpos($img_post->guid, '1.jpg')!== false) || (strpos($img_post->guid, '1.gif')!== false) || (strpos($img_post->guid, '1.png')!== false))){
          $stuff = $img_post->guid;
          wp_delete_attachment($img_post->ID);
        } 
      }
    }
} wp_reset_postdata();

Leave a Reply

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