Answers.Body: <p>Looks like you're trying to access an entries' <em>descendants</em>, which includes all children, children of children and so on. You can get all descendants of an entry using <a href="https://docs.craftcms.com/api/v3/craft-base-elementinterface.html#method-getdescendants" rel="nofollow noreferrer">Entry::getDescendants()</a>:</p>
  <pre class="lang-twig prettyprint-override"><code>{% set rootElement = entry.getAncestors()[0] ?? entry %}
  {% set relatedEntries = rootElement.getDescendants() %}
  </code></pre>
  <p>Note the first line, which will always give you the first-level ancestor of the current entry, even if the current entry is multiple levels down in the hierarchy.</p>
  <p>You can also limit an element query to entries that are descendants of a specific entry. This will allow you to specify additional conditions (like the type), this way you don't have to filter the list afterwards.</p>
  <pre class="lang-twig prettyprint-override"><code>{% set rootElement = entry.getAncestors()[0] ?? entry %}
  {% set relatedEntries = craft.entries()
      .descendantOf(rootElement)
      .type('default')
      .all()
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-21T07:37:18.377Z
Answers.LastActivityDate: 2022-04-21T07:37:18.377Z
Answers.UserDisplayName: MoritzLost
Body: <p>It is possible to get all entries by structureId ?</p>
  <p>If yes how ?</p>
  <p>For now i use something like this:</p>
  <pre><code>{% if entry.parent %}
      {%  set relatedEntries = entry.parent.children()|filter(v =&gt; v.type == 'default')|merge([entry.parent]) %}
  {% else %}
      {% set relatedEntries = entry.children()|filter(v =&gt; v.type == 'default')|merge([entry]) %}
  {% endif %}
  </code></pre>
  <p>But i'm very limited if for example some children entry has children then it doesn't works anymore.</p>
  
Tags: <templating><entries><entry><structure>
Title: Get all entries by structureId
ThreadText: # Get all entries by structureId
  
  (Asked by: username_0 on 2022-04-20)
  
  It is possible to get all entries by structureId ?
  
  If yes how ?
  
  For now i use something like this:
  
  ```
  {% if entry.parent %}
      {%  set relatedEntries = entry.parent.children()|filter(v => v.type == 'default')|merge([entry.parent]) %}
  {% else %}
      {% set relatedEntries = entry.children()|filter(v => v.type == 'default')|merge([entry]) %}
  {% endif %}
  
  ```
  
  But i'm very limited if for example some children entry has children then it doesn't works anymore.
  
  **Tags:** templating, entries, entry, structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-21. Score: 3 | Accepted answer
  
  Looks like you're trying to access an entries' *descendants*, which includes all children, children of children and so on. You can get all descendants of an entry using [Entry::getDescendants()](https://docs.craftcms.com/api/v3/craft-base-elementinterface.html#method-getdescendants):
  
  ```twig
  {% set rootElement = entry.getAncestors()[0] ?? entry %}
  {% set relatedEntries = rootElement.getDescendants() %}
  
  ```
  
  Note the first line, which will always give you the first-level ancestor of the current entry, even if the current entry is multiple levels down in the hierarchy.
  
  You can also limit an element query to entries that are descendants of a specific entry. This will allow you to specify additional conditions (like the type), this way you don't have to filter the list afterwards.
  
  ```twig
  {% set rootElement = entry.getAncestors()[0] ?? entry %}
  {% set relatedEntries = craft.entries()
      .descendantOf(rootElement)
      .type('default')
      .all()
  %}
  
  ```
  
  
  ---
  
  