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.

has_post_thumbnail seems to be working fine but the_post_thumbnail returns nothing.

here is my code:

if ($favorite_post_ids):
    foreach ($favorite_post_ids as $post_id) {
            $p = get_post($post_id);
            echo "<li>";
            echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a> ";
            wpfp_remove_favorite_link($post_id);
            if (has_post_thumbnail($post_id))
            {
                echo $post_id;
                the_post_thumbnail($post_id);
            }
            echo "</li>";
        }

Here is the sample output:

* Post101 remove 101
* Post97 remove 97
* Post59 remove 59

Most of the code above is irrelevant, I just included it for clarity. I have echoed the $post_id to make sure that it is passing the if (has_post_thumbnail($post_id)), which it does but the_post_thumbnail fails silently. I tried echoing it too but that returns nothing either.

I have got post_thumbnails turned on in the theme:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

any ideas? thanks

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You're passing an invalid argument to the_post_thumbnail().

Here's your code: the_post_thumbnail($post_id);

Here's what the_post_thumbnail() expects: the_post_thumbnail( $size, $attr );

The function is expecting a $size as the first argument. Since $post_id is not a valid $size, the function doesn't know what to output.

share|improve this answer
    
You could try echo get_the_post_thumbnail( $id, $size, $attr ); codex.wordpress.org/Function_Reference/get_the_post_thumbnail –  goldenapples Apr 15 '11 at 1:08
    
thanks guys. shoulda looked up the code ref! used this: echo get_the_post_thumbnail( $post_id, 'thumbnail' ); –  edzillion Apr 15 '11 at 13:59

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.