Fix missing media info and thumbnails in WordPress 3.4.x

Does your WordPress media library look like this photo? Maybe you don’t have the same affinity for the BMW 1M that I do, but if you’re missing thumbnails, I might be able to help.

After upgrading an important installation to WordPress 3.4, I suddenly noticed that many thumbnails had disappeared, specifically the earlier uploads. After posting to WP support forum and WP StackExchange group and receiving minimal response, I decided to take a look at the database myself.

I ended up finding the problem in the wp_postmeta table. It turns out that prior versions of WordPress didn’t insert the _wp_attached_file meta key when uploading a photo, and the latest version requires it. Since this key doesn’t exist for some uploads, the system defaults to showing the media icon, and refuses to display resized images in other posts.

The solution is to run through the list of attachments and insert this meta key where it doesn’t exist. I wrote code to do so, and it worked for me, but when another user requested it in a more useable format, I wrapped it in a basic WordPress plugin.

Download it here

I can’t provide much in the way of support for it, but if it fixes your problem, leave a comment.

Tagged with: , , ,
14 comments on “Fix missing media info and thumbnails in WordPress 3.4.x
  1. guest says:

    just wanted to say that I have this problem on one of my blogs and this plugin just says “0 attachments were updated, 2683 were skipped and 0 had errors.” and doesn’t seem to do anything else.

    hope other have better luck. maybe I have a different problem.

  2. wesgood says:

    Does the media icon look the same? Are you able to access the database? If you can, open the table called wp_postmeta and look for keys marked _wp_attached_file. The absence of this key is what the plugin updates. If not, perhaps I can help you repair another problem with the installation.

  3. James Fishwick says:

    I get: 0 attachments were updated, 5517 were skipped and 0 had errors.

    Yet my database has entries like this for meta_value:

    a:6:{s:5:”width”;s:3:”170″;s:6:”height”;s:2:”94″;s:14:”hwstring_small”;s:23:”height=’70’ width=’128′”;s:4:”file”;s:20:”2009/01/img_1188.jpg”;s:5:”sizes”;a:2:{s:9:”thumbnail”;a:3:{s:4:”file”;s:0:””;s:5:”width”;s:3:”150″;s:6:”height”;s:2:”94″;}s:34:”cat_post_thumb_sizecategoryposts-3″;a:3:{s:4:”file”;s:0:””;s:5:”width”;s:3:”150″;s:6:”height”;s:2:”94″;}}s:10:”image_meta”;a:10:{s:8:”aperture”;s:1:”8″;s:6:”credit”;s:0:””;s:6:”camera”;s:27:”Canon EOS DIGITAL REBEL XTi”;s:7:”caption”;s:0:””;s:17:”created_timestamp”;s:10:”1217418562″;s:9:”copyright”;s:0:””;s:12:”focal_length”;s:3:”246″;s:3:”iso”;s:3:”400″;s:13:”shutter_speed”;s:6:”0.0004″;s:5:”title”;s:0:””;}}

  4. Wes says:

    there are multiple entries in the meta table for each attachment. I think there’s one that says wp_attached_post and another with the meta data you’ve sent here. Are you still seeing the error with all 5517 posts skipped?

  5. Dan says:

    I had this exact problem. You saved me an absolute ton of time, thank you!

  6. Dave Goodman says:

    Thank you SOOOOOO much Wes – worked a treat!

  7. martin says:

    Hi there,
    I have the same issue but the script is not working.
    When I go to Settings > Media updater I get this
    Notice: Undefined index: action in /home/content/p/r/o/…/wp-media-updater.php on line 26
    How can I fix this?
    I’m running WP 3.5.1

  8. Wes says:

    That error is probably because you have debug mode on. Can you still run the plugin? It shouldn’t prevent it from fixing the images.

  9. Florent says:

    Thanks so much !
    I have this issue because an old wordpress site was hacked and i had to resintall (not upgrade) the lastest version WP3.8.1.

    I had a issue whith your script because the _wp_attachment_metadata meta for images was also missing !
    like _wp_attached_file
    so i did 2 steps :
    1: change your script to :
    $all_attachments = $wpdb->get_results($sql);

    foreach ($all_attachments as $attachment) {
    //$meta = get_post_meta($attachment->ID, “_wp_attachment_metadata”, true);
    $file = (preg_replace(‘@http.*/wp-content/uploads/@’,”,$attachment->guid));
    // verify that the file exists
    $file_path = $upload_dir[‘basedir’] . ‘/’ . $file;
    if (!file_exists($file_path)) {
    else {

    // add the meta value, which returns false if it already exists
    $adding_meta = add_post_meta($attachment->ID, ‘_wp_attached_file’, $file, true);
    if ($adding_meta)
    echo ” . sprintf(“%d attachments were updated, %d were skipped and %d had errors.”, $updated, $skipped, $error) . ”;
    else : ?>

    <form name="updater" method="post" action=" ‘script’)); ?>”>
    <input class='button-primary' type='submit' name='run-script' value='’ id=’submitbutton’ />

    2: I used the plugin regenerate thumbnails to create the other meta missing.


  10. DUDE!

    very cool. totally worked. WP 3.8.1 and library size of 5000+

    i’m still missing titles on them, but i think that’s just a lost cause and unrelated. the titles were missing before i ran your plugin. now I can at least see the damned thumbnails.

  11. Adam Robertson says:

    I used this recently, but had to do something similar to @Florent

    foreach ($all_attachments as $attachment) {
    // get the meta value
    $meta = get_post_meta($attachment->ID, “_wp_attachment_metadata”, true);
    $file = $meta[‘file’];
    $guid = get_the_guid($attachment->ID );
    $meta_guid = str_replace($upload_dir, ”, $guid);

    // verify that the file exists
    $file_path = $upload_dir[‘basedir’] . ‘/’ . $file;
    if (!file_exists($file_path)) {

    else {
    // add the meta value, which returns false if it already exists
    $adding_meta = update_post_meta($attachment->ID, ‘_wp_attached_file’, $meta_guid, ”);
    if ($adding_meta)
    echo ” . sprintf(“%d attachments were updated, %d were skipped and %d had errors.”, $updated, $skipped, $error) . ”;
    else : ?>


  12. Emmit Sam says:

    Hi Mr, Florent.

    Thanks for sharing your information, I got this error while updating the plugin.

    Parse error: syntax error, unexpected ‘@’ in /home/timbercaft/public_html/ELEGANCETREND/wp-content/plugins/Media/wp-media-updater.php on line 38

  13. Zach says:

    Just wanted to leave a note and say this still works as of today. I used it to fix an import from a single site wordpress installation into a multi-site installation, and it fixed every single media post to show thumbnails again, and in the attached posts. Thank you for this work on this plugin.

  14. Wes says:

    Thanks for the feedback, Zach. Good to see that my research continues to work and that it can help others along the way!

Leave a Reply

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