1

Im grabbing entries from two sections and displaying them using the group filter.

{% set entries = craft.entries().section('extendedEvents, festivalEvents')%}
{% set allEvents = entries %}
{% set allEventsBySection = allEvents|group('section') %}

{% for section, eventsInSection in allEventsBySection %}
- results- 
{% endfor %}

No matter what I do the results are coming back ordered as section2 (entry, entry, entry) then section 1 (entry, entry, entry)

How do I affect the order of the sections when displaying the results?

  • Not sure if I got it wrong but what is your goal exactly? Ordering by orderBy({sectionId: SORT_ASC}) in your main Query? – Robin Schambach Mar 12 at 16:48
  • Thanks, that worked - as there were only two sections I just reversed the arrays in the for loop which also did the job – Kevin Mar 12 at 17:31
  • @Kevin Can you add your solution as an official answer? Might end up helping someone in the future. – Brad Bell Mar 13 at 22:04
0

The suggestion to order by sectionId resolved my issue here.

{% set entries = craft.entries().section('extendedEvents, festivalEvents'). orderBy({sectionId: SORT_ASC}) %}

As it was, I was working with two sections, so my quick fix was to simply reverse the order of the output of the for loop...

{% for section, eventsInSection in allEventsBySection | reverse %}

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.