• Resolved Dcone

    (@dcone)


    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!

    https://www.ads-software.com/extend/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Thread Starter Dcone

    (@dcone)

    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.