<p>I would like to thank Michael Rog for supplying an answer at this similar question about SuperSort:</p>
<p><a href="https://craftcms.stackexchange.com/questions/11050/sorting-an-array-of-entries-according-to-a-fixed-list-array-of-items/36981#36981">Sorting an array of entries according to a fixed list/array of items</a></p>
<p>The code that lets me sort by instrument in any order I want:</p>
<pre><code>  {% set relatedMusicians = craft.entries.section('bios').relatedTo(entry)
  .with(['bioPhoto'])
  .all() 
  %}

        {% set sortAsList = [
          &quot;violin&quot;,
          &quot;viola&quot;,
          &quot;cello&quot;,
         ] %}

{% set sortedMusicians= relatedMusicians
| supersort('customOrderSortAs', as='{instrument}', comp=sortAsList) %}
</code></pre>

CC BY-SA 4.0
2021-01-13T18:31:05.073Z
2021-01-13T23:00:38.907Z
2021-01-13T23:00:38.907Z
M Smith
<p>I have a page that displays musicians grouped by their musical instrument. I am outputting them grouped by instrument, but I have been asked to sort the instrument groups by a custom order specified by the client. Not alphabetical, but a specified order. How should I handle this? I was using .orderBy(‘instrument asc’) in the query to get them in alphabetical order. Would I be creating an array and then assigning keys to them for the order I want and then order by the numerical keys or something? I haven’t been able to figure it out yet. Code snippet below:</p>
<pre><code>  {% set relatedMusicians=craft.entries.section('bios’)
     .relatedTo(entry)
     .orderBy('instrument asc')
     .with(['bioPhoto'])
     .all() 
  %}
</code></pre>

CC BY-SA 4.0
2021-01-12T06:59:21.343Z
What field type do you use for _instrument_?
Oli
CC BY-SA 4.0
2021-01-12T14:37:33.870Z
Plain text; I thought of a dropdown but there are lots of possible instruments and there might be more added down the road, so plain text is what I did.
M Smith
CC BY-SA 4.0
2021-01-12T15:30:40.497Z
I'd recommend another field type if at all possible. Categories or even related entries (structure) will give you far more flexibility than a plain text field. Are you still in a position to change that?
Oli
CC BY-SA 4.0
2021-01-12T19:13:16.507Z
I could conceivably change the field type, yes. That being said, please note that each musical group’s leader wants their instrumental groups in a different order, so the clarinets might be at the top of one group’s list and the bottom of another’s... so setting up a structure might not do the trick...? Or maybe there is a way? I’m quite open to suggestions... I saw this old post about a SuperSort plugin and I wonder if it could be a possible start... https://craftcms.stackexchange.com/questions/11050/sorting-an-array-of-entries-according-to-a-fixed-list-array-of-items?rq=1
M Smith
<templating><sorting><plugin-supersort>
Custom sort order?
# Custom sort order?

(Asked by: username_0 on 2021-01-11)

I have a page that displays musicians grouped by their musical instrument. I am outputting them grouped by instrument, but I have been asked to sort the instrument groups by a custom order specified by the client. Not alphabetical, but a specified order. How should I handle this? I was using .orderBy(‘instrument asc’) in the query to get them in alphabetical order. Would I be creating an array and then assigning keys to them for the order I want and then order by the numerical keys or something? I haven’t been able to figure it out yet. Code snippet below:
  {% set relatedMusicians=craft.entries.section('bios’)
     .relatedTo(entry)
     .orderBy('instrument asc')
     .with(['bioPhoto'])
     .all() 
  %}

**Tags:** templating, sorting, plugin-supersort

> **Comments:**
> **username_1**: What field type do you use for _instrument_?  
> **username_0**: Plain text; I thought of a dropdown but there are lots of possible instruments and there might be more added down the road, so plain text is what I did.  
> **username_1**: I'd recommend another field type if at all possible. Categories or even related entries (structure) will give you far more flexibility than a plain text field. Are you still in a position to change that?  
> **username_0**: I could conceivably change the field type, yes. That being said, please note that each musical group’s leader wants their instrumental groups in a different order, so the clarinets might be at the top of one group’s list and the bottom of another’s... so setting up a structure might not do the trick...? Or maybe there is a way? I’m quite open to suggestions... I saw this old post about a SuperSort plugin and I wonder if it could be a possible start... https://craftcms.stackexchange.com/questions/11050/sorting-an-array-of-entries-according-to-a-fixed-list-array-of-items?rq=1  

---

## 1 answers

### Answer by username_0 on 2021-01-13. Score: 2

I would like to thank Michael Rog for supplying an answer at this similar question about SuperSort:
Sorting an array of entries according to a fixed list/array of items
The code that lets me sort by instrument in any order I want:
  {% set relatedMusicians = craft.entries.section('bios').relatedTo(entry)
  .with(['bioPhoto'])
  .all() 
  %}

        {% set sortAsList = [
          "violin",
          "viola",
          "cello",
         ] %}

{% set sortedMusicians= relatedMusicians
| supersort('customOrderSortAs', as='{instrument}', comp=sortAsList) %}


---

