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
}
?>
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:
Right before:
And then see if
has_post_thumbnail()
returnstrue
?Or, try passing the
$post->ID
to your call tohas_post_thumbnail()
?Try removing $post->ID from the has_post_thumbnail(). Perhaps the $post object isn’t referencing your current post.
Add this at the top of your functions.php