5

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 %}<a href="{{ prev.url }}">&lt;</a>{% endif %}
{% if next %}<a href="{{ next.url }}">&gt;</a>{% endif %}
Anna_MediaGirl
  • 2,503
  • 2
  • 17
  • 45

1 Answers1

7

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
}) %}
Anna_MediaGirl
  • 2,503
  • 2
  • 17
  • 45