<p>There's a method available to all element queries called <code>getDescendants()</code> (or like any method in Yii you can omit the <code>get</code> prefix and use <code>descendants()</code>):</p>
<pre class="lang-twig prettyprint-override"><code>{% for child in craft.entries.id([4,35]).descendants().all() %}
    &lt;pre&gt;{{ dump(child.title) }}&lt;/pre&gt;
{% endfor %}
</code></pre>
<p>You can also pass in a <code>distance</code> integer if you want to limit to direct children/grandchildren.</p>
<p><a href="https://craftcms.com/docs/4.x/elements.html#methods" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/elements.html#methods</a></p>

CC BY-SA 4.0
2023-06-05T09:10:54.567Z
This is exactly what I was looking for! Thank you :)
SplendidRob
CC BY-SA 4.0
2023-06-05T15:26:08.157Z
Although saying that having just tried this it only returns the parent entry...no child entries are output using the above...
SplendidRob
CC BY-SA 4.0
2023-06-05T15:34:06.133Z
hm, I tested this and it worked ok for me. What version of Craft are you using?
James Smith
CC BY-SA 4.0
2023-06-07T08:54:46.600Z
Craft version: Craft Pro 4.4.13
Have tried a variety of things and can only return the parent entry. Interestingly looking through the docs and trying getAncestors() returns an error: Calling unknown method: craft\elements\db\EntryQuery::getAncestors()
SplendidRob
CC BY-SA 4.0
2023-06-07T10:25:36.517Z
Are _all_ of the entries you're querying part of a Craft Structure? Those methods are only available to such elements.
James Smith
CC BY-SA 4.0
2023-06-01T13:56:21.527Z
2023-06-01T13:56:21.527Z
James Smith
<p>Why don't you get the children from each entry individually and then merge them together like so:</p>
<pre><code>{% set childrenOne = craft.entries.id(entryID).one().children.all() %}
{% set childrenTwo = craft.entries.id(entryID).one().children.all() %}

{% set allChildren = childrenOne|merge(childrenTwo) %}
</code></pre>

CC BY-SA 4.0
2023-06-03T08:38:51.187Z
Beware that pretty much every time you write `.one()` or `.all()`, you are executing DB queries... and fairly heavy ones in the case of element queries. So I wouldn't recommend this way. You could mitigate slightly by eager loading the children: `craft.entries.id(entryID).with('children').one()`, but still not great.
James Smith
CC BY-SA 4.0
2023-06-01T15:18:52.820Z
2023-06-01T15:18:52.820Z
Droemmelbert
<p>I'm sure this must be simple but I've tried multiple options with little success. What is the best way to build a query to get the children of more than one entry via an entry field?</p>
<p>For one parent would be:</p>
<pre><code>{% set parent = craft.entries.id(parent_id).one() %}
{% for child in parent.children.all() %}
//Stuff
{% endfor %}
</code></pre>
<p>But I cant work out how to build the initial query to include more than one parent entry. The output I am looking for is a query that allows me to loop through all of the children from both(or more) entries selected. eg:</p>
<pre><code>{% set query = craft.entries.id([4,35]).all().children.all() %}
</code></pre>
<p>Any help much appreciated!</p>

<elementquery>
Get children of multiple entries
# Get children of multiple entries

(Asked by: username_0 on 2023-06-01)

I'm sure this must be simple but I've tried multiple options with little success. What is the best way to build a query to get the children of more than one entry via an entry field?
For one parent would be:
{% set parent = craft.entries.id(parent_id).one() %}
{% for child in parent.children.all() %}
//Stuff
{% endfor %}

But I cant work out how to build the initial query to include more than one parent entry. The output I am looking for is a query that allows me to loop through all of the children from both(or more) entries selected. eg:
{% set query = craft.entries.id([4,35]).all().children.all() %}

Any help much appreciated!

**Tags:** elementquery

---

## 2 answers

### Answer by username_1 on 2023-06-01. Score: 2 | Accepted answer

There's a method available to all element queries called getDescendants() (or like any method in Yii you can omit the get prefix and use descendants()):
{% for child in craft.entries.id([4,35]).descendants().all() %}
    {{ dump(child.title) }}
{% endfor %}

You can also pass in a distance integer if you want to limit to direct children/grandchildren.
https://craftcms.com/docs/4.x/elements.html#methods

> **Comments:**
> **username_0**: This is exactly what I was looking for! Thank you :)  
> **username_0**: Although saying that having just tried this it only returns the parent entry...no child entries are output using the above...  
> **username_1**: hm, I tested this and it worked ok for me. What version of Craft are you using?  
> **username_0**: Craft version: Craft Pro 4.4.13 Have tried a variety of things and can only return the parent entry. Interestingly looking through the docs and trying getAncestors() returns an error: Calling unknown method: craft\elements\db\EntryQuery::getAncestors()  
> **username_1**: Are _all_ of the entries you're querying part of a Craft Structure? Those methods are only available to such elements.  

---

### Answer by username_2 on 2023-06-01. Score: 1

Why don't you get the children from each entry individually and then merge them together like so:
{% set childrenOne = craft.entries.id(entryID).one().children.all() %}
{% set childrenTwo = craft.entries.id(entryID).one().children.all() %}

{% set allChildren = childrenOne|merge(childrenTwo) %}

> **Comments:**
> **username_1**: Beware that pretty much every time you write `.one()` or `.all()`, you are executing DB queries... and fairly heavy ones in the case of element queries. So I wouldn't recommend this way. You could mitigate slightly by eager loading the children: `craft.entries.id(entryID).with('children').one()`, but still not great.  

---

