1

I'm trying to get prev/next entry using positionedAfter and positionedBefore filters but getting weird order on results because order('postDate desc') seems to be ignored.

{% set prevSibling = craft.entries.positionedAfter(entry).order('postDate desc').first() %}

{% set nextSibling = craft.entries.positionedBefore(entry).order('postDate desc').first() %}

Can anyone help?

1 Answer 1

2

positionedAfter only applies to entries within a structure section (https://craftcms.com/docs/templating/craft.entries#positionedAfter). See this answer for how to get next and previous entries.

2
  • Thanks that answer helped, but I still see problem in craft core because I am using structure and order is wrong for positionedAfter and positionedBefore
    – Andris
    Commented Sep 27, 2017 at 12:10
  • 1
    positionedAfter and positionedBefore will return the entry before/after in the Structure in the CMS, regardless of how you order them on the front end using .order(). If you're using this for a blog, you should be using a channel rather than a structure. Commented Sep 27, 2017 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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