Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to retrieve the thumbnails for only certain products of my woocommerce, using products_tag,

this code is showing all products :

<ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>



<?php global $post; echo "<p id = 'id_name'>" . $thePostID = $post->ID. " </p>";    ?>


<?php if (has_post_thumbnail( $loop->post->ID )) 
echo  get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); 
else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />';
?>




<?php endwhile; ?>
</ul><!--/.products-->

I try to add more arguments to the array inserting 'product_tag' but doesn't' work:

 $args = array( 'post_type' => 'product', 'posts_per_page' => 5, product_tag => 'shoes' );

How can i show only the products with the tag shoes ?

Thanks for your help

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I found the answer, it was a typing mistake, you have to put

'product_tag' => 'wherever_tag_you_use' 

and it's works like charm

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.