<p>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.</p>
<p>Example:</p>
<ul>
<li>Category 1
<ul>
<li>Subcategory a</li>
<li>Subcategory b</li>
</ul>
</li>
<li>Category 2
<ul>
<li>Subcategory c</li>
<li>Subcategory d</li>
</ul>
</li>
</ul>
<p>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.</p>
<p>When the user clicks <code>Category 1</code> I want to a query to return <code>Subcategory a</code> and <code>Subcategory b</code>.</p>
<p>When the user clicks <code>Category 1</code> AND <code>Category 2</code> I want to a query to return <code>Subcategory a</code>, <code>Subcategory b</code>, <code>Subcategory c</code> and <code>Subcategory d</code>.</p>
<p>My query:</p>
<pre><code>{% set typeOptions = craft.entries()
 .section('categories')
 .orderBy('title ASC')
 .descendantOf(subcategories|join(','))
 .descendantDist(1)
%}
</code></pre>
<p>The reason why I am using <code>join</code> is because <code>descendantOf</code> 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.</p>
<p>How do I fix this?</p>

CC BY-SA 4.0
2023-09-22T18:25:28.773Z
Can you let us know what subcategories is defined as in your codebase? Seeing how you defined it will help us know what data type it is and whether that's a factor
cherrykoda
CC BY-SA 4.0
2023-09-27T09:22:50.503Z
It's all just a big structured section. And I'm trying to get the title field.
Matthias
CC BY-SA 4.0
2023-10-01T14:53:29.367Z
Right, but how are you calling it? Depending how it could be an object, an ID value...
cherrykoda
<craft4><plugin-sprig><descendantof>
Does descendantOf only accept a single value?
# Does descendantOf only accept a single value?

(Asked by: username_0 on 2023-09-15)

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?

**Tags:** craft4, plugin-sprig, descendantof

> **Comments:**
> **username_1**: Can you let us know what subcategories is defined as in your codebase? Seeing how you defined it will help us know what data type it is and whether that's a factor  
> **username_0**: It's all just a big structured section. And I'm trying to get the title field.  
> **username_1**: Right, but how are you calling it? Depending how it could be an object, an ID value...  

---

## 0 answers

