Azad Chouhan
Azad Chouhan

Reputation: 290

How to fetch the woocommerce product image from wp_query

Hi I am inflating the dropdown the woocommerce product titles with the below code

<select Name='choose' id="chooseme">
  <?php
  $args = array( 'post_type' => array('product') ,'posts_per_page' => 100);
  $loop = new WP_Query( $args );
   ;
  while ( $loop->have_posts() ) : 
      $loop->the_post();
      echo '<option selected value="'.the_title().'</option>';
  endwhile;
  ?>
</select>

Now I want to get the products Image from this query. Is it possible to get the image also from this code or is there any other solution for this?

Upvotes: 0

Views: 2515

Answers (1)

devpro
devpro

Reputation: 16117

You just need to use get_the_post_thumbnail():

echo get_the_post_thumbnail($loop->post->ID, 'yourTable');

Inside the body of while()

Example:

while ($loop->have_posts()) : $loop->the_post();
    echo get_the_post_thumbnail($loop->post->ID, 'yourTable');
endwhile;

Upvotes: 1

Related Questions