I’m trying to merge two query sources (some entries and some categories) but have them ordered by a shared field that is a date field. Here’s what I have so far:

set classesLocations = craft.entries.section('classes')|merge(craft.categories.group('locations'))`

I can group by the field of course, but not sure that helps me with ordering.

When I try to use .order('startTime') on the merged object I of course get an error, as they have already been automatically converted to an array to perform the merge rather than remaining as objects. And of course doing the order on both set of objects first doesn’t help, because the merge just tacks the merge on to the end.

1 Answer 1


Duplicate? How do I combine search for categories and entries into one set of search results?

You will have to use something like supersort to sort your array.

{% set classesLocations = craft.entries.section('classes')|merge(craft.categories.group('locations'))|supersort('sortAs', '{ startTime }') %}

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.