<p>Duplicate? <a href="https://craftcms.stackexchange.com/questions/9032/how-do-i-combine-search-for-categories-and-entries-into-one-set-of-search-result">How do I combine search for categories and entries into one set of search results?</a></p>

<p>You will have to use something like supersort to sort your array.</p>

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

CC BY-SA 3.0
2016-01-05T08:56:19.440Z
2016-01-05T20:41:47.877Z
2017-04-13T12:51:00.160Z
Spoeken
<p>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:</p>

<pre><code>set classesLocations = craft.entries.section('classes')|merge(craft.categories.group('locations'))`
</code></pre>

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

<p>When I try to use <code>.order('startTime')</code> 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.</p>

<templating><entries><categories><ordering><merge>
Order merged query by shared field
# Order merged query by shared field

(Asked by: username_0 on 2015-12-14)

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.

**Tags:** templating, entries, categories, ordering, merge


---

## 1 answers

### Answer by username_1 on 2016-01-05. Score: 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 }') %}


---

