Hierarchical category filters missing on brand archives
Hi,
I found an issue with hierarchical taxonomy filters when using a Shop Archive template and template set for a Brands taxonomy.
The template contains a Filters element alongside Shop Products. The Categories filter is configured as:
- Filter by: Taxonomy
- Taxonomy: Product categories
- Field type: Checkbox
Products and other filters display correctly, but the Categories filter disappears entirely on the brand archive. It displays in the builder’s general shop preview.
Changing the field type to Switch makes the categories appear, but we need the hierarchical checkbox layout. Toggling “Exclude parent taxonomy terms” makes no difference.
Example scenario
Consider this category structure:
Clothing
└── Outerwear
├── Jackets
└── Coats
A product belongs to Brand A and is assigned only to Jackets. Coats contains products from Brand B.
On the Brand A archive, the expected category filter would show:
Clothing
└── Outerwear
└── Jackets
Instead, the Categories field can disappear completely.
Why the current code appears to fail
In sc_filters() in functions/theme-shortcodes.php, Checkbox, Radio and Select fields set:
$terms_params['parent'] = 0;
On an archive, the query also adds:
$terms_params['object_ids'] = $product_ids;
Together, these request only top-level terms directly assigned to products in the current archive.
In the example, the product is directly assigned to Jackets, not Clothing. The query therefore returns no root terms, and the filter field is omitted.
Proposed change
For hierarchical controls:
- Fetch the terms assigned to the archive’s products, without the top-level restriction.
- Add their ancestors so the hierarchy can be displayed.
- Restrict the root query and every child query to that combined set.
This preserves the relevant hierarchy without introducing unrelated branches. It uses the selected taxonomy rather than hard-coding brands or product categories.
The proposed minimal diff against 28.5.10 is:
--- a/functions/theme-shortcodes.php
+++ b/functions/theme-shortcodes.php
@@
if( ( is_tax() || is_tag() || is_category() || is_archive() ) && !empty($product_ids) ) {
//$terms = mfn_get_available_attr_terms_in_current_view($product_ids, $excl_ids, $field['tax_filter'], $hierarchical);
$terms_params['object_ids'] = $product_ids;
+
+ if( isset($terms_params['parent']) ) {
+ $term_ids = get_terms(array_merge($terms_params, [
+ 'parent' => '',
+ 'fields' => 'ids',
+ 'hierarchical' => false,
+ ]));
+
+ if( is_wp_error($term_ids) || empty($term_ids) ) continue;
+
+ $included_ids = $term_ids;
+ foreach( $term_ids as $term_id ) {
+ $included_ids = array_merge(
+ $included_ids,
+ get_ancestors($term_id, $field['tax_filter'], 'taxonomy')
+ );
+ }
+
+ unset($terms_params['object_ids']);
+ $terms_params['include'] = array_unique($included_ids);
+ $terms_params['hide_empty'] = false;
+ }
}
@@
- $term->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $term->term_id]);
+ $term->childrens = get_terms(array_merge($terms_params, [ 'parent' => $term->term_id ]));
@@
- $termm->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $termm->term_id]);
+ $termm->childrens = get_terms(array_merge($terms_params, [ 'parent' => $termm->term_id ]));
@@
- $termmm->childrens = get_terms([ 'taxonomy' => $field['tax_filter'], 'hide_empty' => true, 'parent' => $termmm->term_id]);
+ $termmm->childrens = get_terms(array_merge($terms_params, [ 'parent' => $termmm->term_id ]));
Could you review this approach and consider incorporating a fix into the theme? I’ll leave the final implementation and wider compatibility/regression testing with your team.
This has been applied and working in my current setup at [Links visible only for registered users]
Thanks!
Comments
Hi,
Thanks for letting us know.
I have passed it on to the dev team, and we will take a look at this.
Best regards
Thank you!