Get first image of custom post type wordpress

0 Votes
    916 Views

I have this code

function display_categoria($args) {
$query = new WP_Query(array(
    'post_type' => 'job_listing',
    'post_status' => 'publish',
    'posts_per_page' => 5
));


while ($query->have_posts()) {
  echo $query->the_post();
   $id=get_the_id();
   echo $query1=get_permalink();
  }

 wp_reset_query();
}

add_shortcode( 'este', 'display_categoria' );

in theory i can solve it placing in the loop

 if ( has_post_thumbnail() ) {
the_post_thumbnail();
                            } 

but many entries not have a thumbnail (featured images), Can understand?

1

Answers


Please signup or login to answer this question.