0

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

4

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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