<p>Not really feasible without a plugin – fortunately, there's the excellent <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow">SuperSort</a>:</p>

<pre><code>{% set results =  craft.entries.section('player').search('team:"thenameoftheteam"') %}

{% set resultsByPlayerPosition = entries|supersort('sortAs', '{playerPosition}') %}
{% set resultsByPlayerHeight = entries|supersort('sortAs', '{playerHeight}') %}
{% set resultsByPlayerBirth = entries|supersort('sortAs', '{playerBirth}') %}
</code></pre>

<p>If you need the sorted results in the opposite order, you can just apply the <code>|reverse</code> filter, i.e. </p>

<pre><code>{% set resultsByPlayerHeight = entries|supersort('sortAs', '{playerHeight}')|reverse %}
</code></pre>

<p>If e.g. <code>playerPosition</code> is a relational field (a category, perhaps), you'll need to do something like this:</p>

<pre><code>{% set resultsByPlayerPosition = entries|supersort('sortAs', '{{ playerPosition.first.title }}') %}
</code></pre>

CC BY-SA 3.0
2016-08-24T10:18:22.097Z
2016-08-24T10:18:22.097Z
Mats Mikkel Rummelhoff
<p>I need to order the results of a search query <em>after</em> I got back the results. The reason to do this is that I want to make different lists on the same page (with the same results) and I dont't want to search over and over again just to reorder te results. Can I do that? So basically I do this:</p>

<pre><code>{% set results =  craft.entries.section('player').search('team:"thenameoftheteam"') %}
</code></pre>

<p>What I want to do with this result is:
loop</p>

<ul>
<li>through the results and order them by <code>playerPosition</code></li>
<li>show the longest player (lengths are in the field <code>playerHeight</code>)</li>
<li>show the oldest player (birth dates are in the field <code>playerBirth</code>)</li>
</ul>

<p>I could run this query 3 times and order by a different field each time, but I don't think that's the way to go.</p>

<search><filter>
Order by fields after searching
# Order by fields after searching

(Asked by: username_0 on 2016-08-24)

I need to order the results of a search query after I got back the results. The reason to do this is that I want to make different lists on the same page (with the same results) and I dont't want to search over and over again just to reorder te results. Can I do that? So basically I do this:
{% set results =  craft.entries.section('player').search('team:"thenameoftheteam"') %}

What I want to do with this result is:
loop

through the results and order them by playerPosition
show the longest player (lengths are in the field playerHeight)
show the oldest player (birth dates are in the field playerBirth)

I could run this query 3 times and order by a different field each time, but I don't think that's the way to go.

**Tags:** search, filter


---

## 1 answers

### Answer by username_1 on 2016-08-24. Score: 3 | Accepted answer

Not really feasible without a plugin – fortunately, there's the excellent SuperSort:
{% set results =  craft.entries.section('player').search('team:"thenameoftheteam"') %}

{% set resultsByPlayerPosition = entries|supersort('sortAs', '{playerPosition}') %}
{% set resultsByPlayerHeight = entries|supersort('sortAs', '{playerHeight}') %}
{% set resultsByPlayerBirth = entries|supersort('sortAs', '{playerBirth}') %}

If you need the sorted results in the opposite order, you can just apply the |reverse filter, i.e. 
{% set resultsByPlayerHeight = entries|supersort('sortAs', '{playerHeight}')|reverse %}

If e.g. playerPosition is a relational field (a category, perhaps), you'll need to do something like this:
{% set resultsByPlayerPosition = entries|supersort('sortAs', '{{ playerPosition.first.title }}') %}


---

