<p>You can only pass <a href="https://github.com/brandonkelly/TwigForDesigners/blob/master/values-expressions-and-variables.md#objects"><strong>an object</strong></a> or an ElementCriteriaModel (what you get when you type 'craft.entries') into <code>getNext()</code> and <code>getPrev()</code>. </p>

<p>Calling <code>find()</code> on an ElementCriteriaModel, as I'm doing in my code, turns it into an actual array of entries, which is not something <code>getNext()</code> and <code>getPrev()</code> can work with. </p>

<p>So changing the first line to this will work:</p>

<pre><code>{% set params = craft.entries.section('leadership').leadershipType(entry.leadershipType) %}
</code></pre>

<p>Or this using the object syntax for setting parameters:</p>

<pre><code>{% set params = craft.entries({
    section: 'leadership',
    leadershipType: entry.leadershipType
}) %}
</code></pre>

CC BY-SA 3.0
2014-06-12T17:28:59.397Z
we had [exactly the same question](http://craftcms.stackexchange.com/questions/52/how-to-link-to-previous-next-entries-in-a-section) this morning already :)
carlcs
CC BY-SA 3.0
2014-06-12T17:32:46.820Z
I saw that when posting. My question adds the need to limit by a specific field which is why I posted a new question.
Anna_MediaGirl
CC BY-SA 3.0
2014-06-12T17:08:21.347Z
2014-06-12T17:35:22.637Z
2014-06-12T17:35:22.637Z
Anna_MediaGirl
<p>I'm adding prev/next links to a detail page and can't get <code>craft.entries</code> to return the correct entries.</p>

<p><strong>Specifically, I need <code>craft.entries</code> to return entries in the "leadership" section where the <code>leadershipType</code> field matches the current entry's <code>leadershipType</code> value.</strong></p>

<p>My code returns all entries instead of the ones specific to my field parameter.</p>

<pre><code>{% set params = craft.entries.section('leadership').find({ leadershipType:entry.leadershipType }) %}

{% set prev = entry.getPrev(params) %}
{% set next= entry.getNext(params) %}?

{% if prev %}&lt;a href="{{ prev.url }}"&gt;&amp;lt;&lt;/a&gt;{% endif %}
{% if next %}&lt;a href="{{ next.url }}"&gt;&amp;gt;&lt;/a&gt;{% endif %}
</code></pre>

CC BY-SA 3.0
2014-07-15T22:17:16.513Z
Sorry for that stupid edit I made yesterday, Anna! Must have been very confused with something.
carlcs
CC BY-SA 3.0
2014-07-15T22:29:34.417Z
No problem. Probably my field name using "type" is confusing.
Anna_MediaGirl
<pagination><previous-next>
How can I show next/previous paging that's limited by specific criteria?
# How can I show next/previous paging that's limited by specific criteria?

(Asked by: username_0 on 2014-06-12)

I'm adding prev/next links to a detail page and can't get craft.entries to return the correct entries.
Specifically, I need craft.entries to return entries in the "leadership" section where the leadershipType field matches the current entry's leadershipType value.
My code returns all entries instead of the ones specific to my field parameter.
{% set params = craft.entries.section('leadership').find({ leadershipType:entry.leadershipType }) %}

{% set prev = entry.getPrev(params) %}
{% set next= entry.getNext(params) %}?

{% if prev %}<{% endif %}
{% if next %}>{% endif %}

**Tags:** pagination, previous-next

> **Comments:**
> **username_1**: Sorry for that stupid edit I made yesterday, Anna! Must have been very confused with something.  
> **username_0**: No problem. Probably my field name using "type" is confusing.  

---

## 1 answers

### Answer by username_0 on 2014-06-12. Score: 7 | Accepted answer

You can only pass an object or an ElementCriteriaModel (what you get when you type 'craft.entries') into getNext() and getPrev(). 
Calling find() on an ElementCriteriaModel, as I'm doing in my code, turns it into an actual array of entries, which is not something getNext() and getPrev() can work with. 
So changing the first line to this will work:
{% set params = craft.entries.section('leadership').leadershipType(entry.leadershipType) %}

Or this using the object syntax for setting parameters:
{% set params = craft.entries({
    section: 'leadership',
    leadershipType: entry.leadershipType
}) %}

> **Comments:**
> **username_1**: we had [exactly the same question](http://craftcms.stackexchange.com/questions/52/how-to-link-to-previous-next-entries-in-a-section) this morning already :)  
> **username_0**: I saw that when posting. My question adds the need to limit by a specific field which is why I posted a new question.  

---

