Here are some thoughts :
- the_post_thumbnail() already echo so you cannot echo again
- you could use echo get_the_post_thumbnail() instead
But in your case I don’t really see why you use get_posts()
most of the time we use it to get post data and make other treatments. You’d better use your own instance of WP_Query here like this :
<?php
$_posts = new WP_Query (
array(
'nopaging' => true,
'post_type' => 'services',
'tax_query' => array(
array(
'taxonomy' => 'service_categories',
'field' => 'name',
'terms' => $device_name,
)
)
)
);
if ( $_posts->have_posts() ) :
while ( $_posts->have_posts() ) : $_posts->the_post(); ?>
<div class="devices_name_" style="cursor: pointer">
<?php if ( has_post_thumbnail() ) : ?>
<div><?php the_post_thumbnail(); ?></div>
<?php endif; ?>
<?php the_title(); ?>
<input type="hidden" value="<?php the_ID(); ?>" class="devices_ids_"/>
</div>
<?php endwhile; wp_reset_postdata();
endif;
this way you could use functions that work within the loop. Be careful the_post_thumbnail() takes a size parameter. By default it’s “post-thumbnail” size.