Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am currently upgrading my WP to 3.2.1 to 3.5.2, and for one section of my posts it seems like the featured image has disappeared. However, I just checked the the wp_posts table in the database through phpmyadmin and looked for one of my posts that had this issue. My img tags are being produced dynamically, but the problem is that the src is blank. Here's an example of one of the posts:

Given this record in my wp_posts table:

    ID     post_author  post_date   post_date_gmt   post_content    post_title  post_excerpt    post_status     comment_status  ping_status     post_password   post_name   to_ping     pinged  post_modified   post_modified_gmt   post_content_filtered   post_parent     guid                                                 menu_order     post_type   post_mime_type  comment_count   cod_current_ahrf 
    16169  1            2011-06-17  2011-06-17                      Nick-Arias                  inherit         close           close                           Nick-Arias.jpg          0000-00-00 00:00:00     0000-00-00 00:00:00                         3728            /images/ahrf/pioneers/legends_face/Nick-Arias.jpg    0              attachment  image/jpeg      0   

category-legends.php:

if(file_exists($_SERVER{'DOCUMENT_ROOT'}.substr($fivesdraft->guid_legend,20)))
    {
    echo $fivesdraft->ID; // returns 3728
    $featured = gangmei_get_the_post_thumbnail_url( $fivesdraft->ID );          
    echo '<li class="legends-thumb"><div class="img-wrapper"><a href="/?legends='.$fivesdraft->post_name.'"><img src="'.$featured.'" alt="'.$fivesdraft->name.'" /></div><p><a href="/?legends='.$fivesdraft->post_name.'">'.$fivesdraft->name.'</a></p></li>';
    } 

functions.php:

    function gangmei_get_the_post_thumbnail_url($post_id = NULL) {
        global $id;
        $post_id = (NULL === $post_id) ? $id : $post_id;
        $edmund = get_post_thumbnail_id($post_id);
        echo "post_id = $post_id"; // returns 3728
        echo "edmund = $edmund"; // returns 16169
        $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full'); //the issue arises here. this returns nothing.
        $src = $src[0];
        return $src;

    }

This is what is produced: <img src="" alt="Nick Arias">. What's supposed to be produced is this: <img alt="Nick Arias" src="/images/ahrf/pioneers/legends_face/Nick-Arias.jpg">

The thing is that under the guid column in the database you can see the value of that column for that record is /images/ahrf/pioneers/legends_face/Nick-Arias.jpg. Is it possible to just grab the guid instead of going through all of these functions? Like this:

$featured = $fivesdraft->guid;?

share|improve this question
add comment

3 Answers

you need to echo it.

example:

<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');?>
<img src="<?php echo $src[0] ?>" />
share|improve this answer
    
The problem is $src isn't returning anything. It's not even an array like it's supposed to be. It's just blank, so echoing it wouldn't do anything. –  Edmund Jul 3 '13 at 15:11
add comment
up vote 0 down vote accepted

So I figured it out. What I did to fix this was simplify the whole thing:

if(file_exists($_SERVER{'DOCUMENT_ROOT'}.substr($fivesdraft->guid_legend,20))
    {
    $thumbnail_id = get_post_thumbnail_id($fivesdraft->ID);
    $featured = wp_get_attachment_url( $thumbnail_id );

    //$featured = gangmei_get_the_post_thumbnail_url( $fivesdraft->ID );

    echo '<li class="legends-thumb"><div class="img-wrapper"><a href="/?legends='.$fivesdraft->post_name.'"><img src="'.$featured.'" alt="'.$fivesdraft->name.'" /></div><p><a href="/?legends='.$fivesdraft->post_name.'">'.$fivesdraft->name.'</a></p></li>';
    } 

No clue why the old version worked for 3.2.1 and not 3.5.2 though.

share|improve this answer
    
Using that susbstring like that looks dicey but I can't say for sure without knowing what $fivesdraft looks like. –  s_ha_dum Jul 3 '13 at 16:07
add comment

Your code works when I try it with a post ID known to have a "Featured" image. It is possible that you have a database problem but that isn't the table you'd find it, probably. Look in $wpdb->postmeta for a k ey named _thumbnail_id and a post_id matching a post you think should have a thumbnail. If that isn't there your post has lost its "Featured" image somehow and you need to fix that. My guess is that you problem is here.

Jumping from 3.2.1 to 3.5.2 is a huge jump. A lot has changed. If you have a backup of the database, I'd suggest resetting to 3.2.1 and incrementally updating through each release until you get current. If that is not possible you may have to debug and repair problem by problem.

Couple of other things:

Is it possible to just grab the guid instead of going through all of these functions?

The guid is not an URL. Don't let the fact that it looks like one confuse you.

Is there a different way to grab a thumbnail image than this?

There are other ways to do it, yes, depending on what you want. You can go straight to complete markup with get_the_post_thumbnail, for example.

share|improve this answer
    
Thanks sha. I posted my solution as an answer to this question, could you check if it's ok? Will it change anything moving forward or does it work the same? –  Edmund Jul 3 '13 at 15:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.