<p>Because the <code>descendantOf</code> function expects a parameter of type <code>ElementInterface</code> or an integer</p>

<pre><code> /**
 * Sets the [[descendantOf]] property.
 *
 * @param int|ElementInterface|null $value The property value
 *
 * @return static self reference
 */
public function descendantOf($value);
</code></pre>

<p>You'll have to insert the ID of your <code>accessories</code> element or the element itself</p>

<pre><code>{% accessories = craft.categories.title('accessories').first() %}
{% set categoryGroup = craft.categories.group('productTypes').descendantOf(accessories) %}
</code></pre>

CC BY-SA 3.0
2018-03-19T11:14:49.970Z
2018-03-19T11:14:49.970Z
Robin Schambach
<p>I would like to select just the children of any given main category (eg. Accessories, Stomps in the picture), regardless of segments in my URL.</p>

<p>I've been trying to understand why the code below won't work.</p>

<p><a href="https://i.sstatic.net/z84Mf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/z84Mf.png" alt="I would like to select just the children of any given main category (eg. Accessories, Stomps"></a></p>

<p>This just won't work. Why?</p>

<pre><code>{% set categoryGroup = craft.categories.group('productTypes').descendantOf('accessories') %}
&lt;ul&gt;
    {% for category in categoryGroup %}
        &lt;li class="category"&gt;{{ category.title }}&lt;/li&gt;    
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<children>
Get category children
# Get category children

(Asked by: username_0 on 2018-03-19)

I would like to select just the children of any given main category (eg. Accessories, Stomps in the picture), regardless of segments in my URL.
I've been trying to understand why the code below won't work.

This just won't work. Why?
{% set categoryGroup = craft.categories.group('productTypes').descendantOf('accessories') %}

    {% for category in categoryGroup %}
        {{ category.title }}    
    {% endfor %}

**Tags:** children

---

## 1 answers

### Answer by username_1 on 2018-03-19. Score: 2 | Accepted answer

Because the descendantOf function expects a parameter of type ElementInterface or an integer
 /**
 * Sets the [[descendantOf]] property.
 *
 * @param int|ElementInterface|null $value The property value
 *
 * @return static self reference
 */
public function descendantOf($value);

You'll have to insert the ID of your accessories element or the element itself
{% accessories = craft.categories.title('accessories').first() %}
{% set categoryGroup = craft.categories.group('productTypes').descendantOf(accessories) %}


---

