Looper that includes certain taxonomies but excludes other

I know another user brought this up in this post but is there a way to still implement this using a Query String?

I was thinking something like this might work:

product_cat={{dc:term:name}}=all-products&category__not_in=stuff-to-filter-out&post_type=product&posts_per_page=8&orderby=asc

But alas the category_not_in part of the code doesn’t do anything.

Hey @dobacco,

Thanks for writing in!

There is something wrong with the query string. It should be:
product_cat={{dc:term:name}}&post_type=product&posts_per_page=8&orderby=asc

The category__not_in will only accept an array of category IDs.

Best Regards.

Thanks for the reply.

I did try changing the string query and attached &category__not_in%5B0%5D=134 where 134 is the category to exclude but it does not seem to do anything. I understand what’s suggested in that link but I’m not sure how to implement.

Hello @dobacco,

As it turns out, you are working with the product taxonomy. Therefore, the catgeory__not_in will not work. You need to have an argument just like this:

$args = array(
    'post_type' => 'product',
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'term_id',
            'terms' => array(134),
            'operator' => 'NOT IN',
        ),
    ),
);

And this will give you:
post_type=product&tax_query%5B0%5D%5Btaxonomy%5D=product_cat&tax_query%5B0%5D%5Bfield%5D=term_id&tax_query%5B0%5D%5Bterms%5D%5B0%5D=134&tax_query%5B0%5D%5Boperator%5D=NOT+IN

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.