WooCommerce sidebar filter widgets with per-taxonomy selection rules
Published Updated 3 min read
WooCommerce ships a Product Categories widget and a Layered Navigation widget, and neither lets you set a selection rule. Both behave the same whatever they filter: a visitor clicks a term, the page reloads, that term is active. You cannot make one widget replace its selection on each click while another adds to it.
Print-on-demand stores hit this constantly. The catalogue has two cross-cutting taxonomies, product type (hoodie, shirt, sweatshirt) and design theme (cat, dog, bird). A visitor looking at hoodies expects clicking 'shirt' to replace 'hoodie', not add to it. The same visitor who picked 'cat' expects 'dog' to widen the results to both, not narrow them to nothing. Two rules, and no built-in widget can express either.
A small plugin registers a sidebar widget you can place as many times as you like. Each instance has its own taxonomy and its own mode: single-select, which replaces the selection on every click, or multi-select OR, which adds and removes terms and shows everything matching any of them.
Categories widget, Layered Navigation and the big filter plugins
The Product Categories widget goes to the category archive and has no multi-select. Clicking a subcategory replaces the view; there is no way to show two categories at once.
Layered Navigation filters by product attributes, the pa_color and pa_size WooCommerce generates, not by product_cat or custom taxonomies registered outside the attribute system.
WOOF, FacetWP and YITH Product Filter solve all of this, with admin screens, database tables, settings to manage and prices out of proportion to the problem. For a store that needs two widgets with different rules, the dependency is bigger than the job.
Replace or accumulate
Each WC Taxonomy Filter widget takes three settings: the heading shown in the sidebar, a taxonomy slug (product_cat, product_tag, or any custom taxonomy on your site) and a selection mode.
Single-select works like radio buttons. The active term is in bold; clicking another moves to a URL where only that term is active, and clicking the active one clears the filter.
Multi-select OR works like a checklist. Each click adds or removes a term, and the archive shows every product in any active term: cat and dog shows all the cat products and all the dog products, not only products that are both.
Filter state lives in the URL, so the back and forward buttons behave, and each term shows its product count. It works on the shop archive and on any taxonomy archive.
Two widgets for a print-on-demand sidebar
In Appearance > Widgets, drag a WC Taxonomy Filter into the shop sidebar, give it a heading, enter the taxonomy slug and choose the mode. Repeat for each taxonomy. A typical print-on-demand store needs two: product type on single-select and design theme on multi-select OR. Each widget manages its own URL parameter.
Filtered URLs look like ?filter_product_cat=hoodies&filter_design=cat,dog. Most caching plugins treat each as a separate page and cache it correctly. If you see stale results after filtering, check that your cache is not normalising or stripping query strings.
Attributes, AND logic and page reloads
Product attributes stay with Layered Navigation. Both widgets use filter_ parameters for different things and sit happily in the same sidebar.
There is no AND mode. A product needs to match only one selected term, not all of them. Strict intersection would mean a third mode that switches the WP_Query operator from IN to AND, and across many terms it often returns few or no products, which confuses visitors unless the catalogue is built for it.
Every selection reloads the page; there is no live AJAX filtering. With a few hundred products on a standard host the reload is quick enough that few visitors notice. With tens of thousands of products and heavy queries, a follow-up message can add AJAX filtering as a second pass.
What you get
Included
- Configurable sidebar widget with display name, taxonomy slug, and selection mode
- Single-select mode: one active term at a time, clicking another replaces it
- Multi-select OR mode: multiple terms active simultaneously, each click adds or removes
- URL query parameter-based filter state, works with browser back and forward navigation
- Compatible with any registered WordPress taxonomy including product categories
Not included
- WooCommerce product attributes (pa_color, pa_size): use the built-in Layered Navigation widget for those
- AND logic between selected terms: multi-select uses OR only
- AJAX live filtering: each selection requires a page reload
- Price range, stock status, or rating filtering
- Integration with FacetWP, WOOF, or YITH Product Filter
Questions
Can I filter by a custom taxonomy I registered myself?
Yes. Enter the slug exactly as you passed it to register_taxonomy. Any taxonomy attached to the product post type works, whether you or a plugin created it.
Why do filters work on page one of the archive but not page two?
WooCommerce builds pagination links from its own URL structure and can drop query string parameters along the way. Carrying the filter parameters forward needs a filter on those pagination links.
Can I use it to filter ordinary blog posts?
Not as built. The pre_get_posts hook only acts on WooCommerce shop and taxonomy archives. Filtering other archives needs a shortcode version that renders the list inline and uses the same URL parameters.
Build it in Steem
The button opens the builder with this guide's prompt filled in, so you can change anything before it runs. Nothing is built, and nothing is charged, until you send it.
Read the prompt (489 words)
Build a WordPress plugin called WC Taxonomy Filter. Plugin Name: WC Taxonomy Filter. Description: A sidebar widget that filters WooCommerce products by any registered taxonomy, with configurable single-select or multi-select OR selection rules. Single PHP file. Register a widget class WC_Taxonomy_Filter_Widget that extends WP_Widget. Constructor: id_base 'wc_taxonomy_filter', name 'WC Taxonomy Filter', description 'Filters WooCommerce products by taxonomy with configurable selection rules'. Widget form (backend, method form($instance)): render three fields. First: text input for key 'title', label 'Display Name', default empty. Second: text input for key 'taxonomy', label 'Taxonomy slug (e.g. product_cat)', default 'product_cat'. Third: select input for key 'mode', label 'Selection mode', options are value 'single' with label 'Single-select (replace on click)' and value 'multi_or' with label 'Multi-select OR (add or remove)'. Use $this->get_field_id() and $this->get_field_name() for each field. Widget update (method update($new_instance, $old_instance)): return array with title => sanitize_text_field($new_instance['title']), taxonomy => sanitize_key($new_instance['taxonomy']), mode => in_array($new_instance['mode'], ['single','multi_or']) ? $new_instance['mode'] : 'single'. Widget widget (method widget($args, $instance)): read $title = $instance['title'] ?? '', $taxonomy = $instance['taxonomy'] ?? 'product_cat', $mode = $instance['mode'] ?? 'single'. Get terms: $terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => true]). If is_wp_error($terms) or empty($terms), return. Echo $args['before_widget']. If $title is non-empty, echo $args['before_title'] . esc_html($title) . $args['after_title']. Determine active selections from URL. The query parameter for each taxonomy is 'filter_' . $taxonomy. For single mode: $active = sanitize_key($_GET['filter_' . $taxonomy] ?? ''). For multi_or mode: $raw = $_GET['filter_' . $taxonomy] ?? ''; $active = array_filter(array_map('sanitize_key', explode(',', $raw))). Render: echo '<ul style="list-style:none;margin:0;padding:0;">'. For each $term in $terms, determine $is_active. For single mode: $is_active = ($active === $term->slug). For multi_or mode: $is_active = in_array($term->slug, $active, true). Build toggle URL. For single mode: if $is_active, $url = remove_query_arg('filter_' . $taxonomy); else $url = add_query_arg('filter_' . $taxonomy, $term->slug). For multi_or mode: $new_set = $is_active ? array_values(array_diff($active, [$term->slug])) : array_values(array_merge($active, [$term->slug])); if empty $new_set, $url = remove_query_arg('filter_' . $taxonomy); else $url = add_query_arg('filter_' . $taxonomy, implode(',', $new_set)). Note: add_query_arg and remove_query_arg with no third argument use the current request URI as the base URL. Render each term as: '<li><a href="' . esc_url($url) . '"' . ($is_active ? ' style="font-weight:bold;color:#0073aa;"' : '') . '>' . esc_html($term->name) . ' <span style="color:#999;font-size:0.9em;">(' . intval($term->count) . ')</span></a></li>'. After the loop, echo '</ul>' and $args['after_widget']. Register a function wc_taxonomy_filter_pre_get_posts hooked on pre_get_posts at priority 10. In this function: return if is_admin(). Return if not $query->is_main_query(). Return if not (function_exists('is_shop') && (is_shop() || is_product_taxonomy() || is_product_category())). Collect all $_GET keys that start with 'filter_'. For each such key: $taxonomy_name = sanitize_key(substr($key, 7)); if empty $taxonomy_name, skip. $raw = $_GET[$key]; $slugs = array_filter(array_map('sanitize_key', explode(',', $raw))); if empty $slugs, skip. Build a tax_query entry: ['taxonomy' => $taxonomy_name, 'field' => 'slug', 'terms' => array_values($slugs), 'operator' => 'IN']. Collect all entries into $new_entries. If $new_entries is non-empty: $existing = $query->get('tax_query') ?: []; $merged = array_merge($existing, $new_entries); $merged['relation'] = 'AND'; $query->set('tax_query', $merged). At the bottom of the file: add_action('widgets_init', function(){ register_widget('WC_Taxonomy_Filter_Widget'); }); add_action('pre_get_posts', 'wc_taxonomy_filter_pre_get_posts'); No database writes. No admin menu. No settings page.
Steem