I am trying to apply the group filter so that my year headings appear in DESC order. They are appearing in ASC order instead, and applying |reverse doesn't work. Suggestions?

{% set entries = craft.entries.section('blat')
.orderBy('postDate DESC')
.with ( ['thumbnail'] )
{% set entriesByYear = entries|group('postDate.year') %}
{% for year, entriesInYear in entriesByYear %}

    <h2>{{ year }}</h2>

  {% for entry in entriesInYear %}

{% endfor %}

You don't mention where you tried putting the reverse filter, but perhaps you put it in the wrong place? It should go here:

{% set entriesByYear = entries|reverse|group('postDate.year') %}

I've tested this and it works ok for me.

  • i am wondering why orderBy to desc is not working in question though?
    – user9975
    May 28 '20 at 10:28

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.