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?


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.

  • 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
    Sep 27 '17 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. Sep 27 '17 at 12:49

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.