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 %}
  • Sorry for that stupid edit I made yesterday, Anna! Must have been very confused with something. – carlcs Jul 15 '14 at 22:17
  • No problem. Probably my field name using "type" is confusing. – Anna_MediaGirl Jul 15 '14 at 22:29
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
}) %}
  • 2
    we had exactly the same question this morning already :) – carlcs Jun 12 '14 at 17:28
  • 1
    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 Jun 12 '14 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.