I am trying to get the featured images of custom post type images. I am using this code. All of my posts have images but I am unable to show.
<?php
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'services',
'tax_query' => array(
array(
'taxonomy' => 'service_categories',
'field' => 'name',
'terms' => $device_name,
)
)
)
);
//show devices
//print_r($posts_array);
foreach ($posts_array as $key) {
//print_r($key);
if ( has_post_thumbnail() ) {
the_post_thumbnail();
echo "yahoo";
}
?><div class="devices_name_" style="cursor: pointer">
<div><?php echo the_post_thumbnail($key->ID); ?></div>
<?php echo $key->post_title; ?>
<input type="hidden" value="<?php echo $key->ID; ?>" class="devices_ids_"/>
</div>
<?php
}
?>
echo get_the_post_thumbnail($key->ID)
and see if you get the image? Justthe_post_thumbnail()
is used in the loop with WP_Query