I have a products page on which I'm filtering with Sprig. There are some categories in the form of checkboxes. These categories have some subcategories. The categories are a structured section with nested categories.
Example:
- Category 1
- Subcategory a
- Subcategory b
- Category 2
- Subcategory c
- Subcategory d
What I currently got working is to show the level 2 categories filters based on the chosen main category. What does not work is doing the same but for 2 main categories at the same time.
When the user clicks Category 1
I want to a query to return Subcategory a
and Subcategory b
.
When the user clicks Category 1
AND Category 2
I want to a query to return Subcategory a
, Subcategory b
, Subcategory c
and Subcategory d
.
My query:
{% set typeOptions = craft.entries()
.section('categories')
.orderBy('title ASC')
.descendantOf(subcategories|join(','))
.descendantDist(1)
%}
The reason why I am using join
is because descendantOf
does not accept an array and it seems it also does not accept comma separated string.
It does accept a non comma separated string. I'm guessing it converts it to an INT internally.
How do I fix this?