<p><code>nextSiblingOf()</code> and related methods will only work with Structure entries. What you need instead is <code>next() / prev()</code>: <a href="https://docs.craftcms.com/api/v3/craft-base-element.html#next" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-base-element.html#next</a></p>
<p>(At the time of writing, the 3.x docs seem to be lacking any detail on next/prev methods, but the 2.x docs seem to cover it here:
<a href="https://craftcms.com/docs/2.x/templating/entrymodel.html#getnext-params" rel="nofollow noreferrer">https://craftcms.com/docs/2.x/templating/entrymodel.html#getnext-params</a>)</p>
<p>So in your case it'd look like this:</p>
<pre><code>{% set siblingsQuery = craft.entries.id(10).one().projects %}
{% set next = entry.next(siblingsQuery) ?? siblingsQuery.one() %}

</code></pre>
<p>Note the lack of <code>.all()</code> at the end of my first line - <code>next() / prev()</code> take an <strong>unexecuted</strong> element query as an argument.</p>

CC BY-SA 4.0
2022-01-16T23:56:36.577Z
That did the trick. Thank James.
Benek Lisefski
CC BY-SA 4.0
2022-01-14T09:25:41.113Z
2023-12-19T20:48:41.227Z
2023-12-19T20:48:41.227Z
James Smith
<p>I have an index of projects that uses a standard entries field to select multiple entries to display and also provides a custom order (different to their Structure order). This is my &quot;Projects&quot; page.</p>
<p>Then each of those entries has its own &quot;Project Details&quot; page. On the Project Detail template, I need to determine the &quot;next&quot; project in the parent page's entries field order in relation to the current entry - and also revert to showing the first project as &quot;next&quot; if the current entry is the last and has no next sibling.</p>
<p>I've tried code like this (where ID &quot;10&quot; is the &quot;Work&quot; page with the entries field, and &quot;projects&quot; is the entries field handle)...</p>
<pre><code>{% set parent = craft.entries().id(10).one() %}
{% set siblings = parent.projects.all() %}
{% set next = siblings.nextSiblingOf(entry).one() %}
{% if next is null %}
  {% set next = parent.projects.one() %}
{% endif %}
</code></pre>
<p>The problem here is that <code>siblings</code> is an array and not an element query, and I get this error:</p>
<blockquote>
<p>Impossible to invoke a method (&quot;nextSiblingOf&quot;) on an array.</p>
</blockquote>
<p>Is there a way to do something similar to <code>nextSiblingOf()</code> on an array? Or is there a way to output the entries from that &quot;projects&quot; field as a query so that I can use <code>nextSiblingOf()</code> as I've tried above?</p>

<craft3><templating><entries><entries-field><previous-next>
How to find next sibling from entry order of parent entries field
# How to find next sibling from entry order of parent entries field

(Asked by: username_0 on 2022-01-14)

I have an index of projects that uses a standard entries field to select multiple entries to display and also provides a custom order (different to their Structure order). This is my "Projects" page.
Then each of those entries has its own "Project Details" page. On the Project Detail template, I need to determine the "next" project in the parent page's entries field order in relation to the current entry - and also revert to showing the first project as "next" if the current entry is the last and has no next sibling.
I've tried code like this (where ID "10" is the "Work" page with the entries field, and "projects" is the entries field handle)...
{% set parent = craft.entries().id(10).one() %}
{% set siblings = parent.projects.all() %}
{% set next = siblings.nextSiblingOf(entry).one() %}
{% if next is null %}
  {% set next = parent.projects.one() %}
{% endif %}

The problem here is that siblings is an array and not an element query, and I get this error:

Impossible to invoke a method ("nextSiblingOf") on an array.

Is there a way to do something similar to nextSiblingOf() on an array? Or is there a way to output the entries from that "projects" field as a query so that I can use nextSiblingOf() as I've tried above?

**Tags:** craft3, templating, entries, entries-field, previous-next

---

## 1 answers

### Answer by username_1 on 2022-01-14. Score: 6 | Accepted answer

nextSiblingOf() and related methods will only work with Structure entries. What you need instead is next() / prev(): https://docs.craftcms.com/api/v3/craft-base-element.html#next
(At the time of writing, the 3.x docs seem to be lacking any detail on next/prev methods, but the 2.x docs seem to cover it here:
https://craftcms.com/docs/2.x/templating/entrymodel.html#getnext-params)
So in your case it'd look like this:
{% set siblingsQuery = craft.entries.id(10).one().projects %}
{% set next = entry.next(siblingsQuery) ?? siblingsQuery.one() %}


Note the lack of .all() at the end of my first line - next() / prev() take an unexecuted element query as an argument.

> **Comments:**
> **username_0**: That did the trick. Thank James.  

---

