Title: Custom loop using multiple categories
Last modified: August 20, 2016

---

# Custom loop using multiple categories

 *  Resolved [Dcone](https://wordpress.org/support/users/dcone/)
 * (@dcone)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-loop-using-multiple-categories/)
 * I’m trying to create a loop filtering by multiple categories.
 * I have the two product category slugs saved as variables.
 * Here are some loop args that work for me with just one category:
 *     ```
       <?php
       $args = array('post_type' => 'product', 'product_cat' => $catOne);
       ?>
       ```
   
 * But how do I filter by two categories? I have tried the following with no luck:
   `'
   product_cat' => array($catOne, $catTwo)`
 * Any help would be greatly appreciated, thanks!
 * [http://wordpress.org/extend/plugins/woocommerce/](http://wordpress.org/extend/plugins/woocommerce/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [Dcone](https://wordpress.org/support/users/dcone/)
 * (@dcone)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-loop-using-multiple-categories/#post-3503434)
 * I was able to solve my problem using the following:
 *     ```
       <?php
       $args = array(
         'post_type' => 'product',
         'posts_per_page' => -1,
         'tax_query' => array(
           'relation' => 'AND',
           array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => $catOne
           ),
           array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => $catTwo
           )
         )
       );
       ?>
       ```
   
 * Hope it helps someone else!

Viewing 1 replies (of 1 total)

The topic ‘Custom loop using multiple categories’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [custom loop](https://wordpress.org/support/topic-tag/custom-loop/)
 * [multiple categories](https://wordpress.org/support/topic-tag/multiple-categories/)
 * [product_cat](https://wordpress.org/support/topic-tag/product_cat/)

 * 1 reply
 * 1 participant
 * Last reply from: [Dcone](https://wordpress.org/support/users/dcone/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/custom-loop-using-multiple-categories/#post-3503434)
 * Status: resolved