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.

OK, I got a custom post type with thumbnail enabled which adds the "featured images" panel to that post-type just fine, but in my template when I do

if ( has_post_thumbnail() ) {
    the_post_thumbnail();
} else {
    echo 'none';
}

it just shows 'none' on each one even though I have a featured image set... I have add_theme_support('post-thumbnails',array('post','custom_post_type')); so it's supported by the theme but has_post_thumbnail always returns false what's going on here???

My template is : archive-custom_post_type.php :

<?php
$loop = new WP_Query(array( 'post_type' => 'clients', 'posts_per_page' => -1 ));
if($loop){
?>
<ul>
<?php
while ( $loop->have_posts() ) : $loop->the_post();
?>
        <li>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
            <?php 
                if ( has_post_thumbnail($post->ID) ) {
                    the_post_thumbnail('thumbnail');
                    echo get_post($post->ID)->post_excerpt;
                } else {
                    echo 'broken ::' . $post->ID;
                    echo get_post($post->ID)->post_excerpt;
                }

            ?>
            </a>
        </li>
<?php 
endwhile;
//wp_reset_postdata();
?>
</ul>
<?php
}
?>
share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

In your Custom Post Type, do you setup_postdata( $post ) in your custom Loop? If not, has_post_thumbnail() might not be defined/available?

EDIT:

Try adding:

setup_postdata( $post );

Right before:

$loop->the_post();

And then see if has_post_thumbnail() returns true?

Or, try passing the $post->ID to your call to has_post_thumbnail()?

has_post_thumbnail( $post->ID );
share|improve this answer
    
No I dont, I've updated the question with the full page –  JKirchartz May 31 '11 at 20:32
    
Then try adding setup_postdata( $post ); (I think, right before $loop->the_post()) –  Chip Bennett May 31 '11 at 21:08
    
nope, still returning 'none' –  JKirchartz May 31 '11 at 21:11
    
Is that both for using setup_postdata(), and for passing $post->IDto has_post_thumbnail()? Another question: are the_permalink() and the_title_attribute() working? –  Chip Bennett May 31 '11 at 21:15
1  
the_post() method calls setup_postdata() by itself, no need to add it. –  Rarst May 31 '11 at 21:17
show 2 more comments

Try removing $post->ID from the has_post_thumbnail(). Perhaps the $post object isn't referencing your current post.

share|improve this answer
add comment

Add this at the top of your functions.php

if( ! function_exists( 'has_post_thumbnail' ) )
{
    function has_post_thumbnail( $pid )
    {       
        return get_post_meta( $pid, '_thumbnail_id', true );
    }
}
share|improve this answer
    
In the OPs case, has_post_thumbnail returned false incorrectly at all times. It didn't throw a Call to undefined function error. Please explain how your above code block would be of help to this issue. –  Johannes Pille Apr 16 '13 at 15:37
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.