WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This code is from the archive page and list all products with a certain tag, can someone please help me to modify this code to make listing products only from current category:

<?php if ( is_product_tag() ) :?>   
    <?php do_action('woocommerce_before_shop_loop'); ?>
        <ul class="products">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php woocommerce_get_template_part( 'content', 'product'); ?>
            <?php endwhile; // end of the loop. ?>
    <?php do_action('woocommerce_after_shop_loop'); ?>
<?php endif; ?>
share|improve this question
WooCommerce already supports product listing by product category. No need to modify any code at all. – Stephen Nov 6 '12 at 15:01
But I need a filter by category and tag, not only by category – Dime Nov 6 '12 at 15:14
Just to clarify. You want to show all products within a category that have a specific tag? – Stephen Nov 6 '12 at 15:40
yes, can you help me? – Dime Nov 6 '12 at 15:52
up vote 0 down vote accepted

Your best bet to do this would be to add a filter/hook on the specific tag. See this snippet at the WooCommerce API docs site on excluding a category for the proper format and to get going in the right direction. http://wcdocs.woothemes.com/snippets/exclude-a-category-from-the-shop-page/

But if you want a down and dirty way to filter for a specific tag on this content part then you can wrap an if then around your woocommerce_get_template_part().

<?php while ( have_posts() ) : the_post(); ?>
    <?php if ( *** product has tag *** ) { ?>
            <?php woocommerce_get_template_part( 'content', 'product'); ?>
    <?php endif; ?>
<?php endwhile; // end of the loop. ?>

You can look at the API docs on the product tags at http://wcdocs.woothemes.com/apidocs/class-WC_Product.html#_get_tags

Make sure you're following WooCommerce theme customization recommendations at http://wcdocs.woothemes.com/codex/template-structure/

Unless you want this to be global you'll have to account for the various outputs and determine when you don't want to filter both products and tags.

share|improve this answer
Thanks, I will try that – Dime Nov 7 '12 at 10:21

Your Answer


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.