<p>I was able to accomplish this by just adding both variables to my SuperSort tag. In essence, what I did was this:</p>

<pre><code>{% set fruits = fruits | supersort('natsortas', '{count} {title}') %}
</code></pre>

<p>It seems to be working in my situation, but if there's a better way to do it, I'm open to suggestions.</p>

CC BY-SA 3.0
2015-10-22T17:25:12.040Z
I changed the sort method to "natsort", to make this work with count numbers greater than 9.
carlcs
CC BY-SA 3.0
2015-10-22T17:32:23.377Z
There's one problem with this approach. The supersort "as" methods generate a string form the 2nd parameter and use that to sort by. So it basically compares "2 pineapples", "4 grapefruits", "2 apples",... Because of that you can't have different sort orders for each property, so it's either both ascending or not.
carlcs
CC BY-SA 3.0
2015-10-22T16:42:33.817Z
2015-10-22T17:21:06.050Z
2015-10-22T17:21:06.050Z
Andrew Philpott
<p>I just gave it a play and found a simple solution to get them ordered by count in descending order
and them by title in ascending order:</p>

<pre><code>{% set fruits = fruits|supersort('natsortas', '{{ (9999-object.count) ~ object.title }}') %}
</code></pre>

CC BY-SA 3.0
2015-10-22T18:01:39.207Z
2015-10-22T18:01:39.207Z
carlcs
<p>Is there a way with SuperSort to sort an array by multiple variables? For example, let's I have the following data and I want to sort by count and then alphabetically:</p>

<pre><code>pineapples (2)
grapefruits (4)
apples (2)
bananas (3)
</code></pre>

<p>Ideally, I would want that to be sorted as:</p>

<pre><code>grapefruits (4)
bananas (3)
apples (2)
pineapples (2)
</code></pre>

<plugin-supersort>
SuperSort - Sort by multiple variables
# SuperSort - Sort by multiple variables

(Asked by: username_0 on 2015-10-22)

Is there a way with SuperSort to sort an array by multiple variables? For example, let's I have the following data and I want to sort by count and then alphabetically:
pineapples (2)
grapefruits (4)
apples (2)
bananas (3)

Ideally, I would want that to be sorted as:
grapefruits (4)
bananas (3)
apples (2)
pineapples (2)

**Tags:** plugin-supersort


---

## 2 answers

### Answer by username_0 on 2015-10-22. Score: 4

I was able to accomplish this by just adding both variables to my SuperSort tag. In essence, what I did was this:
{% set fruits = fruits | supersort('natsortas', '{count} {title}') %}

It seems to be working in my situation, but if there's a better way to do it, I'm open to suggestions.

> **Comments:**
> **username_1**: I changed the sort method to "natsort", to make this work with count numbers greater than 9.  
> **username_1**: There's one problem with this approach. The supersort "as" methods generate a string form the 2nd parameter and use that to sort by. So it basically compares "2 pineapples", "4 grapefruits", "2 apples",... Because of that you can't have different sort orders for each property, so it's either both ascending or not.  

---

### Answer by username_1 on 2015-10-22. Score: 1

I just gave it a play and found a simple solution to get them ordered by count in descending order
and them by title in ascending order:
{% set fruits = fruits|supersort('natsortas', '{{ (9999-object.count) ~ object.title }}') %}


---

