Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T17:41:23.640Z
Answers.Text: 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.
Answers.UserDisplayName: Mike Pringle
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T17:13:39.047Z
Answers.LastActivityDate: 2016-01-29T17:13:39.047Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <entries><children>
Title: Get children of specific parent
ThreadText: # 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](https://craftcms.com/docs/templating/elementcriteriamodel) prepared to query for entries matching your criteria. You now have to use the [`first`](https://craftcms.com/docs/templating/elementcriteriamodel#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.  
  
  ---
  
  