How to filter all products by products_tag (woocommerce )

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

1 Answer
1

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

Leave a Comment