WordPress.org

Ready to get started?Download WordPress

Forums

Auto Post Thumbnail
[resolved] WordPress 3.4: Stopped Working, Thumbnails Missing (87 posts)

  1. drummergirl
    Member
    Posted 2 years ago #

    It still doesn't work for me. The images that are not showing for me were ones I attached as a featured image but do not appear in the post. Therefore, regenerating a thumbnail (even after deleting them in bulk) results in no image for those posts.

    The images are there and I can load the url in my browser and see them. They just do not appear in the media library or on the front end. I have been scouring the database trying to find a way to reconnect the dots so they can be seen.

    Any pointers on what/where to look would be great. I don't want to upload them all again (we're talking 500+ products), but I would gladly manually edit the entries to save my image seo. I just don't know what to change to make them work again.

  2. tariquesani
    Member
    Plugin Author

    Posted 2 years ago #

    @drummergirl the plugin will not work if the featured image is not in the post....

  3. drummergirl
    Member
    Posted 2 years ago #

    I get that - but what can I do to fix my current situation? It's clearly a bug in 3.4.

  4. drummergirl
    Member
    Posted 2 years ago #

    I've noticed this... on posts with a missing thumb, in the database there are 11 records for it but only 10 will show in phpmyadmin. On posts with thumbs displaying, all records in the db show for that post.

    I tried repairing the db, but those extra records are still not displaying. I think this may be the missing link in repairing my missing thumbs. Anyone have any experience with something like this? How can I see that extra record?

  5. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    Actually, gothickmatt's fix suggested earlier is more correct than the one currently implemented.

    There's no need to call update_attached_file() explicitly, wp_insert_attachment() would call it for you if the second parameter is not empty:
    http://core.trac.wordpress.org/browser/tags/3.4/wp-includes/post.php#L3772

    The problem is in line 353 of auto-post-thumbnail.php:

    $thumb_id = wp_insert_attachment($attachment, $file, $post_id);

    The $file variable is not defined (you could see that with WP_DEBUG on), it should be $new_file instead.

  6. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    It's clearly a bug in 3.4.

    The related change is that get_attached_file() now only returns the file name if the file actually exists, relying on the correct _wp_attached_file value in the database: http://core.trac.wordpress.org/changeset/20613

    I think this may be the missing link in repairing my missing thumbs.

    Have you tried clickthroughmarketing's fix to restore _wp_attached_file values?

    If that doesn't help, I'd suggest to try Regenerate Thumbnails plugin:
    http://wordpress.org/extend/plugins/regenerate-thumbnails/

  7. drummergirl
    Member
    Posted 2 years ago #

    Thanks - I did try clickthrough's, bu the script runs and nothing changes. I'm running the Regen Thumbnails now and every time it hits one of those broken images I get the following message:

    "Light Red Volleyball" (ID 9560) failed to resize. The error message was: The originally uploaded image file cannot be found at

    I've been working on rebuilding them on by one which sucks, but I can't find any other way to get them back. These are product pages ad I NEED them the thumbnails for the pages to show products.

  8. drummergirl
    Member
    Posted 2 years ago #

    And a few of them that do make it through without an error message, still aren't showing up.

  9. drummergirl
    Member
    Posted 2 years ago #

    As I mentioned earlier, the urls to the image are correct and if I copy/paste it to a browser window, the image will display. I cannot, however, find a record with the url in the database. I think that is where the problem lie. I've tried all kinds of searches for it using partial strings, but never find a record with a url to any of the broken images.

    Surely there has to be something somewhere since it still shows in the media library, right?

  10. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    "Light Red Volleyball" (ID 9560) failed to resize. The error message was: The originally uploaded image file cannot be found at

    Indeed, Regenerate Thumbnails also relies on _wp_attached_file.

    Could you look if those values are present in wp_postmeta for the broken attachments? If they are, what's the _wp_attached_file value for meta_id 9560?

  11. drummergirl
    Member
    Posted 2 years ago #

    Thanks Sergey - I just queried the database and there are no results for _wp_attached_file.

    The only records with a meta_ID 9560 has the meta key "_edit_lock"

    Should I just rebuild these thumbnails manually or is there a way to salvage what I have?

  12. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    The error message implies that 9560 is the "Light Red Volleyball" attachment's ID, however only posts should have _edit_lock meta value, not the attachments. Generally, attachments only have two values: _wp_attachment_metadata and _wp_attached_file.

    Looks like your metadata is somehow malformed, and the problem is a bit different from the one in the Auto Post Thumbnail plugin.

    So I'd suggest rebuilding the thumbnails manually (if that's an acceptable option), or starting a new thread to see if that could bring more attention to the original cause.

  13. drummergirl
    Member
    Posted 2 years ago #

    That's kind of what I figured. I'm about halfway through replacing the product images.

    Fortunately I have them all saved elsewhere and I don't have to go dig through my uploads directory to find each one.

  14. sunriseweb
    Member
    Posted 2 years ago #

    I had a similar, or the same problem. It ended up that the postmeta _wp_attached_file records were missing for all previously uploaded images.

    I ended up using the excellent http://wordpress.org/extend/plugins/regenerate-thumbnails/ plugin with a hack added.

    I edited regenerate-thumbnails.php ajax_process_image() function to add in the following lines immediately after line 360 where the $fullsizepath is determined:

    $fullpathprefix = '/home/myaccount/public_html'; //hard coded base file path
    $fullpathsuffix = substr($image->guid,19,strlen($image->guid)); //hard coded length of 19 based on the base domain (e.g. http://remaxpei.com )
    $fullsizepath = $fullpathprefix.$fullpathsuffix;
    update_attached_file( $image->ID, $fullsizepath );

    Yes - could get the base file path and domain length dynamically - but just hard coded it because one-off use

  15. breravin
    Member
    Posted 2 years ago #

    I've successfully implemented the fix and used clickthroughmarketing's php, however I use higher resolution thumbnails, and they now appear to be much lower resolution.

    Does anyone know why that might be the case? (I figured this was related to this thread, but I can make a new post if this seems too off topic).

    Thank you.

  16. rejeanqc
    Member
    Posted 2 years ago #

    Hi, i got the same problem, i also found that on a majority of my posts, _wp_attached_file was empty while _wp_attachment_metadata was fine. This also after an update to WP3.4 (or so it seems). I do have a number of posts with a thumbnail that show up in a summary page, but the posts themselves don't have an image (to avoid copyright issues).

    This fixed the issue:
    http://wordpress.stackexchange.com/questions/55809/wp-3-4-has-missing-photo-data

    The proposed function goes though the table and updates the fields so they are in synch.

    The question now is why this was broken.

  17. dhobeika
    Member
    Posted 2 years ago #

    Hi all,

    I am having the same problem and just want to make sure I am doing all the steps right.

    I downloaded the fix for 3.4 at http://www.sanisoft.com/downloads/auto-post-thumbnail-for34.zip

    and then did the clickthroughmarketing fix here and ran this php script: http://www.clickthrough-marketing.com/how-to-fix-auto-post-thumbnail-on-wordpress-3.4-seo-friendly-800610805/

    I then went to the auto post thumbnail settings and regenerated the thumbnails and it's still not working.

    Am I doing something wrong? Thanks in advance for any help...

  18. 3c32
    Member
    Posted 2 years ago #

    In case anyone is having this issue independent of this plugin (such as after importing images directly through a custom script during a site transfer), here's how I solved it:


    INSERT INTO
    wp_postmeta
    (post_id,meta_key,meta_value)
    SELECT
    p.ID post_id,
    '_wp_attached_file' meta_key,
    REPLACE(p.guid,'http://www.yoursite.com/wp-content/uploads/','') meta_value
    FROM wp_posts p
    LEFT OUTER JOIN wp_postmeta m
    ON m.post_id=p.ID
    WHERE p.post_type='attachment'
    AND p.post_parent!=0
    AND (SELECT COUNT(e.post_id) FROM wp_postmeta e WHERE e.meta_key='_wp_attached_file' AND e.post_id = p.ID)=0

  19. tariquesani
    Member
    Plugin Author

    Posted 1 year ago #

    Marking this thread as resolved. Create new threads for new issues

  20. Tommy2K
    Member
    Posted 1 year ago #

    Not totally resolved to be honest @3c32's solution worked for me, however, the specific media item needed to be connected to a post, if not, it wouldn't be recovered. Any idea @3c32?

    ------

    EDIT: Found it! Just don't search for a post parent in the query. Like this:

    INSERT INTO wpsteez_postmeta
    (post_id,meta_key,meta_value)
    SELECT
    p.ID post_id,
    '_wp_attached_file' meta_key,
    REPLACE(p.guid,'http://localhost:8888/arcus/wp-content/uploads/','') meta_value
    FROM wpsteez_posts p
    LEFT OUTER JOIN wpsteez_postmeta m
    ON m.post_id=p.ID
    WHERE p.post_type='attachment'
    AND (SELECT COUNT(e.post_id) FROM wpsteez_postmeta e WHERE e.meta_key='_wp_attached_file' AND e.post_id = p.ID)=0
  21. capsx
    Member
    Posted 1 year ago #

    fix.php

    http://paste.php.lv/e89e7b6bf2767cb3b210719e8236456b/nonum

    <?php
    
    //////////////////////////////////////////////////////////////////////
    
    ini_set('display_errors', 1);
    ini_set('error_reporting', 'E_ALL & ~E_NOTICE');
    
    header('Content-Type: text/html; charset=utf-8'); 
    
    //////////////////////////////////////////////////////////////////////
    
    include_once('wp-config.php');
    include_once('wp-load.php');
    include_once('wp-includes/wp-db.php');
    
    //////////////////////////////////////////////////////////////////////
    
    global $wpdb;
    
    $q = "SELECT post_id, meta_value FROM ".$wpdb->postmeta." WHERE meta_key='_wp_attachment_metadata'";
    $myrows = $wpdb->get_results($q);
    $i=0;
    foreach($myrows as $myrow)
    {
    	$id = null;
    	$us = null;
    	$_wp_attached_file = null;
    	$_wp_attached_file_exists = null;
    
    	$us = unserialize($myrow->meta_value);
    	$post_id = $myrow->post_id;
    	$_wp_attached_file = $us['file'] ;
    
    	$q = "SELECT <code>meta_id</code> FROM <code>".$wpdb->postmeta."</code> WHERE <code>meta_key</code> = '_wp_attached_file' AND <code>post_id</code> = '".$post_id."' LIMIT 1";
    	$_wp_attached_file_exists = $wpdb->get_var($q);
    	if($_wp_attached_file_exists=='')
    	{
    		$i++;
    		echo '<p> '.$i.' - _wp_attached_file not found - '.$id.'</p>';
    		$q = "INSERT INTO <code>".$wpdb->postmeta."</code> SET <code>post_id</code> = '".$post_id."', meta_key='_wp_attached_file', meta_value='".$_wp_attached_file."'";
    		$wpdb->query($q);
    	}
    }
    
    //////////////////////////////////////////////////////////////////////
  22. blog4kolkata
    Member
    Posted 1 year ago #

    i always use external images in my posts. but this plugin is not generating thumbnails for url-linked images. is it supposed to generate thumbnails for uploaded images only?

  23. vincej
    Member
    Posted 1 year ago #

    not sure if this can help... but
    I uploaded to 3.4. found same problem with the thumbnails, all disappear.

    After reading the above, I wrote a snippet which I inserted into my single.php page. Since my site is traversed by google daily, I'll let the robots update my meta info.

    My approach is simple. just grab and insert the appropriate meta info into _wp_attached_file with the filename. see code further below for how-to.
    as in.
    Meta ID ID meta key meta value
    2102702 134444 _wp_attached_file 2010/09/desk1-170x146.jpg

    now the question is... do I also have to add the
    _wp_attachment_metadata too?

    My plan is to run this on my 3.3.1 blog for a while, then upgrade to 3.4 when I am sure all my posts have been updated.
    This avoids deleting, regenerating, or even touching my actual images or thumbnails, and switching over to 3.4 only when all is stable.
    NOTE: ASSUMPTION code below will parse out the upload dir based on any blog upload dir which is from year 2000 onwards to 2099.

    if (has_post_thumbnail( $post->ID ) ) {
    $image = wp_get_attachment_image_src(
    $theid = get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
    echo '<br>' . $theid .'<br>' ;
    if (get_post_meta($theid, '_wp_attached_file',  true) == '') { echo "No attached file... inserting now" ; } else { echo "here's the meta: " . get_post_meta($theid, '_wp_attached_file',  true); }
    $thumbnailURL = $image[0];
     $newstring = strstr ($thumbnailURL, "20") ;
    add_post_meta($theid, '_wp_attached_file', $newstring, true);
    }

    NOTE: you can take out the echo statements above... I find them convenient just for debugging, of course.

    By placing this on the single.php page, the job is done automagically for me and I can get back to biz..

    So.. the only question now the question is... do I also have to add the
    _wp_attachment_metadata too?

  24. JonnyDee
    Member
    Posted 1 year ago #

    vincej,

    I am a complete novice to php, and appreciate the share ..
    ""NOTE: ASSUMPTION code below will parse out the upload dir based on any blog upload dir which is from year 2000 onwards to 2099.""

    Can you please modify to include offsite images?

  25. Anest
    Member
    Posted 1 year ago #

    The following script did it for me (handmade).
    What it does is this:
    It selects all post_id values from wp_postmeta which have meta_key _wp_attachment_metadata.
    It then runs a loop checking if there is a row in the table with any of those post_ids that have meta_key _wp_attached_file.
    If there isn't a meta_key _wp_attached_file
    it fetches the guid from wp_posts with id = post_id, removes http://www.YOURDOMAIN.gr/wp-content/uploads/ from the value of guid and inserts a new row at wp_postmeta with meta_key _wp_attached_file and meta_value the substring of the guid.

    NOTE: if your table prefix is not wp_ you should change the lines the words wp_postmeta and wp_posts with those of your mysql tables.

    Also replace first line YOURCONNECTIONSCRIPT.php with your connection to the database and http://www.YOURDOMAIN.com on line 56 with your url.

    Running this scirpt will with those changes will output a list with the post_id, the value to be entered and the query to the database that will add the rows to wp_postmeta. (It will not add anything in the first time). If you want to be sure just do 1 insert manually (take the line from the output and do the query on your db) and check if the post is fixed.
    If yes you should remove the comments on line 63 so the script can run the queries and run it again. You will see again a large output with all the changes.
    Run it again and you ll see nothing. This shows that everything entered as intended.

    Here is the code, i hope i helped.

    <?php require_once('YOURCONNECTIONSCRIPT.php'); ?>
    <?php
    
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    mysql_select_db($database_myconnection, $myconnection);
    $query_Recordset1 = "SELECT post_id FROM wp_postmeta WHERE meta_value like '%jpg%'and meta_key='_wp_attachment_metadata'";
    $Recordset1 = mysql_query($query_Recordset1, $myconnection) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    $counter='0';
     do {
    $postid = $row_Recordset1['post_id']; 
    
    $query_Recordset2 = "SELECT post_id FROM wp_postmeta WHERE post_id ='$postid' AND meta_key='_wp_attached_file'";
    $Recordset2 = mysql_query($query_Recordset2, $myconnection) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    if (!isset($row_Recordset2['post_id'])){
    echo $postid;
    $query_Recordset3 = "SELECT guid FROM wp_posts WHERE id ='$postid'";
    $Recordset3 = mysql_query($query_Recordset3, $myconnection) or die(mysql_error());
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    $totalRows_Recordset3 = mysql_num_rows($Recordset3);
    
    $newguid = str_replace('http://www.YOURDOMAIN.com/wp-content/uploads/', '', $row_Recordset3['guid']); 
    
    echo "   ".$newguid."<br/>";
    echo "INSERT INTO <code>wp_postmeta</code> (<code>meta_id</code> ,<code>post_id</code> ,<code>meta_key</code> ,<code>meta_value</code>) VALUES (NULL ,  '$postid',  '_wp_attached_file',  '$newguid')";
    
    #### REMOVE THE COMMENTS FROM THE NEXT LINE AFTER YOU SEE THE FEEDBACK AND RUN THE SCRIPT AGAIN
    ## mysql_query("INSERT INTO <code>wp_postmeta</code> (<code>meta_id</code> ,<code>post_id</code> ,<code>meta_key</code> ,<code>meta_value</code>) VALUES (NULL ,  '$postid',  '_wp_attached_file',  '$newguid')", $myconnection) or die(mysql_error());
    
    $counter++;
    }
    } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
    echo $counter;
    if ($counter==0){echo "Great success!";}
    ?>
    <?php
    mysql_free_result($Recordset1);
    mysql_free_result($Recordset2);
    ?>
  26. Tevya
    Member
    Posted 1 year ago #

    So rather than trying to catch up on 3 pages of posts, what's the verdict? Is this plugin fixed? Or was it a WP bug, and did 3.4.2 fix it? Where are we at?

  27. tariquesani
    Member
    Plugin Author

    Posted 1 year ago #

    Works fine with 3.5

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic