<p>You need to get the parent entry model before requesting its children with the <code>getChildren</code> method. <code>craft.entries.id(4)</code> only creates a <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">criteria model</a> prepared to query for entries matching your criteria. You now have to use the <a href="https://craftcms.com/docs/templating/elementcriteriamodel#first" rel="nofollow"><code>first</code></a> method to query for an entry model.</p>

<pre><code>{% set parent = craft.entries.id(4).first() %}

{# Check if it indead returned an entry model, could also return nothing #}
{% if parent %}
    {% set children = parent.children %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-01-29T17:41:23.640Z
Thank you!  I tried exactly this but without the .first().  The one thing that still trips me up when working in Craft is remembering that even single results are returned in an array.
Mike Pringle
CC BY-SA 3.0
2016-01-29T17:13:39.047Z
2016-01-29T17:13:39.047Z
carlcs
<p>This one seems deceptively simple, but I am struggling.  My home page is a single, and in that template I want to retrieve the children of a specific entry in a structure, then loop through them.  Here is a code example that does not work:</p>

<pre><code>{% set entries = craft.entries.id(4).children %}
{% for entry in entries %}
    do something
{% endfor %}
</code></pre>

<p>This returns the page with id 4 instead of its children.</p>

<p>I also tried something like:</p>

<pre><code>{% set entries = craft.entries.section('pages').descendantsOf('targetpage') %}
</code></pre>

<p>Maybe I need to retrieve the entire section and do a conditional loop for entries where the parent entry ID is 4, but the proper syntax for that eludes me.</p>

<p>Could someone please point me in the right direction?  Thanks!</p>

<entries><children>
Get children of specific parent
# Get children of specific parent

(Asked by: username_0 on 2016-01-29)

This one seems deceptively simple, but I am struggling.  My home page is a single, and in that template I want to retrieve the children of a specific entry in a structure, then loop through them.  Here is a code example that does not work:
{% set entries = craft.entries.id(4).children %}
{% for entry in entries %}
    do something
{% endfor %}

This returns the page with id 4 instead of its children.
I also tried something like:
{% set entries = craft.entries.section('pages').descendantsOf('targetpage') %}

Maybe I need to retrieve the entire section and do a conditional loop for entries where the parent entry ID is 4, but the proper syntax for that eludes me.
Could someone please point me in the right direction?  Thanks!

**Tags:** entries, children


---

## 1 answers

### Answer by username_1 on 2016-01-29. Score: 3 | Accepted answer

You need to get the parent entry model before requesting its children with the getChildren method. craft.entries.id(4) only creates a criteria model prepared to query for entries matching your criteria. You now have to use the first method to query for an entry model.
{% set parent = craft.entries.id(4).first() %}

{# Check if it indead returned an entry model, could also return nothing #}
{% if parent %}
    {% set children = parent.children %}
{% endif %}

> **Comments:**
> **username_0**: Thank you!  I tried exactly this but without the .first().  The one thing that still trips me up when working in Craft is remembering that even single results are returned in an array.  

---

