WooCommerce Filter OR Logic Between Attributes: How AND/OR Work
When a shopper ticks Red and Blue, HUSKY shows products in either colour. When they tick Red in one attribute and Light in another, only products that are both red and light remain, and often there are none. That is the default WooCommerce filter logic: OR between the values of one attribute, AND between different attributes. Below is how each rule works, how to switch a filter to AND or NOT IN, what happens with parent and child categories, and what you can do when you need OR logic between attributes.
The two rules: OR inside a filter, AND between filters
Every filter block on the page (an attribute, categories, tags, a brand taxonomy) is one group. Values selected inside a group are alternatives; the groups themselves must all match. Selecting Red, Blue, Light and Dark therefore searches for:
(Color = Red OR Color = Blue) AND (Tint = Light OR Tint = Dark)
A plain filter URL shows the same structure: ?swoof=1&pa_color=red,blue&pa_tint=light,dark. A comma joins the values of one taxonomy, and each taxonomy is a separate condition. Price, stock, rating, text search and meta field filters join the search in the same way, each as one more AND condition.
AND between groups is what makes a filter narrow the catalogue: every new choice can only remove products. With OR between attributes, each click would add products instead, and "Red" plus "Size M" would show every red product and every size M product together.
Change the logic inside one filter: OR, AND or NOT IN
The logic inside a group is a setting of that taxonomy. Open the HUSKY settings, go to the Structure tab, click the cog icon (additional options) next to the taxonomy, choose Logic of filtering and save the settings.
| Logic of filtering | Red + Blue selected finds | Use it for |
|---|---|---|
| OR (default) | Products that have Red or Blue | Normal filtering: colours, sizes, brands, categories |
| AND | Only products that have both Red and Blue | Values a product has several of at once: features, equipment, tags, certifications |
| NOT IN | Products that have neither Red nor Blue | Exclusion filters such as "hide these brands" |
Three details decide whether the result looks right:
- AND only makes sense where several values can be selected: Checkbox, Multi drop-down, Label, Color and Image. Keep a taxonomy Slider on OR: a slider selects every value in the range, and no product has all of them. A Multi drop-down set to AND by mistake is the usual reason for "I can select two brands and get nothing": no product belongs to both brands.
- AND does not include subcategories. With OR, WordPress counts a product in a subcategory as part of the parent category. With AND, HUSKY switches that off for the taxonomy, so a product matches only the terms it is assigned to itself. More on this in the next section.
- NOT IN is not a normal filter. Ticking a value hides the products that have it, and the URL key becomes
rev_plus the taxonomy name, for examplerev_product_cat. A category filter left on NOT IN by accident looks broken: clicking a category shows "the same products" or products from other categories.
The numbers next to the values (with Show count and Dynamic recount on) follow the logic too. With OR, the count of an unselected value tells how many of the products matching the other filters have that value; it does not drop when another value of the same group is ticked, because ticking it would add products. With AND, each count shows how many products would remain, so counts fall to 0 quickly, and with Hide empty terms those values disappear after the first click. That is expected; why values disappear after the first selection explains the settings involved.
Older answers on the forum and the AND logic FAQ set AND with the woof_main_query_tax_relations hook. In the current version the Logic of filtering setting feeds that same hook, so the snippet is not needed. If you keep one, merge your values into the array the hook receives instead of returning a fixed list; a fixed list replaces the settings of every other taxonomy. The counts are calculated from the setting, not from the hook, so an AND set only in code shows OR counts.
/*
* Only if you need it in code: AND for tags, keeping the settings
* of all other taxonomies. Child theme functions.php or a code snippets plugin.
*/
add_filter( 'woof_main_query_tax_relations', function ( $relations ) {
$relations['product_tag'] = 'AND';
return $relations;
}, 20 );
Parent and child categories selected together
A frequent surprise with a category tree: the shopper ticks Clothing, then T-shirts inside it, and the result does not get smaller. With OR this is correct. Clothing already includes everything in its subcategories, so adding T-shirts as an alternative changes nothing. HUSKY does not untick the parent automatically. There are three ways to make the second click narrow the result:
- Use a single-choice type for categories: Radio, Drop-down or Hierarchy drop-down. A new choice replaces the previous one. The Hierarchy drop-down shows one drop-down per level and searches only the last level chosen, the way the year, make and model filter works.
- Keep checkboxes and let shoppers untick the parent. This keeps the option of combining two subcategories with OR, for example T-shirts and Shirts.
- Switch categories to AND. Then Clothing + T-shirts finds products assigned to both, which narrows as expected. It works only when every product is assigned to each level of its chain, parent and child ticked on the product, because AND does not include subcategories. A product assigned only to T-shirts is then not found under Clothing, and two sibling subcategories together usually return nothing. Imports often assign only the last level; the FAQ on category hierarchy filtering shows how to assign the parents in bulk.
Single or multiple selection
Whether shoppers can pick one value or several depends on the display type of the taxonomy, chosen on the Structure tab:
- One value: Radio, Drop-down, Hierarchy drop-down, and Radio/Checkbox in drop-down with its Type set to Radio.
- Several values: Checkbox, Multi drop-down, Label, Color, Image, and Radio/Checkbox in drop-down with Type set to Checkbox.
The Label type always allows several selections and has no single-choice mode. For buttons that behave like radio buttons, create an element of the Radio type in the Smart Designer and style it as labels. With a single-choice type only one value is ever selected, so OR and AND find the same products, except that AND drops subcategories as described above.
OR logic between different attributes
There is no setting for OR between two taxonomies: the relation between filter groups is always AND. Before reaching for code, check the data, because the request usually points to how the values are stored:
- Alternatives spread over several taxonomies. If "Helmets" exists in two auction taxonomies and shoppers expect helmets from both, the auctions are values of one question. One taxonomy Auction with both auctions as terms, plus a separate Item type, gives exactly "helmets in auction A or B" with the default settings.
- Unrelated groups in one taxonomy. The opposite mistake: size, colour and style all created as product categories. HUSKY sees one taxonomy and joins every selection with OR, so "8x10" + "Red" + "Traditional" shows anything that has one of them. Move each group into its own attribute and the groups are joined with AND.
- A value that belongs to two choices. If unisex products should appear for both Boys and Girls, assign them both terms instead of a separate Unisex term.
If the catalogue really needs OR across taxonomies, it is custom development: the product query, the counts and the URLs must all be changed together. The hooks involved are woof_get_tax_query for grids rendered by [woof_products], WooCommerce's woocommerce_product_query action for the shop and archive pages, and woof_dynamic_count_attr for the counts. Changing the relation of the whole tax query to OR is not enough on its own, because WooCommerce keeps its product visibility conditions in the same query.
Shortcode taxonomies: comma and plus
The taxonomies attribute of [woof_products] and [woof] uses the same two rules. Terms are given by ID, a comma separates alternatives inside one taxonomy, and a plus sign adds another taxonomy that must also match:
[woof_products per_page=12 taxonomies="product_cat:15,16+pa_color:42"]
This shows products in category 15 or 16 that also have the colour with ID 42. A union of different taxonomies, such as "category 15 or tag 30", cannot be written with this syntax. Term IDs are shown as tag_ID in the address bar when you edit a term.
If the logic seems to be ignored
- Open additional options of each taxonomy on the Structure tab and check Logic of filtering; a forgotten AND or NOT IN is the most common cause of empty or strange results. Save, clear the page cache and reload with Ctrl+F5.
- Remove old
woof_main_query_tax_relationsorwoof_get_tax_querysnippets from the theme that return a fixed array. - With AND on categories, make sure products are assigned to every level of their category chain.
- If selections change the URL but the products never change, whatever the logic, the product grid ignores the filter: see filter URL changes but products are not filtered.
If the results still do not match the logic you set, open a topic on the HUSKY support forum with a filter URL, the expected products and the Logic of filtering of each taxonomy involved.