<p>The probably most easy way to do this is to sort the grouped array by key, which unfortunatelly is only possible with
a plugin, as Twig's <a href="http://twig.sensiolabs.org/doc/filters/sort.html" rel="nofollow noreferrer"><code>sort</code></a> filter only allows to sort by value.</p>

<p>Here I'm using Michael Rog's <a href="https://topshelfcraft.com/lagniappe/supersort" rel="nofollow noreferrer">Supersort</a>, but there are also other plugins that do this.</p>

<pre><code>{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% set allProfilesGrouped = allProfiles|group("profileAlphabet")|supersort('ksort') %}
</code></pre>

CC BY-SA 3.0
2015-05-27T07:10:13.813Z
2017-08-02T17:33:41.170Z
2017-08-02T17:33:41.170Z
carlcs
<p>Stumbled upon this looking to answer similar problem. You should be able to do this now without a plugin, using the <a href="https://craftcms.com/docs/3.x/dev/filters.html#multisort" rel="nofollow noreferrer">multisort filter</a> where you iterate through your profiles, e.g.:</p>
<pre><code>{% for profile in profiles|multisort(['profileLastname'],[SORT_ASC],[SORT_REGULAR]) %}
</code></pre>

CC BY-SA 4.0
2020-11-10T22:51:10.717Z
2020-11-10T22:51:10.717Z
littlered
<p>I need to group and order member profiles alphabetically but I can't get it to work. Have a look here: <a href="http://ffsd.de.w0129b45.kasserver.com/mitglieder" rel="nofollow">http://ffsd.de.w0129b45.kasserver.com/mitglieder</a>
(It's german but you should get the idea :))</p>

<p>In everything I tried either the groups are ordered correctly or the contents (profiles) of the group are… but never both. Here's the relevant code:</p>

<pre><code>{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% for letter, profiles in allProfiles|group("profileAlphabet") %}
    &lt;ul class="member__index"&gt;
        &lt;li class="item letter"&gt;
            &lt;span id="{{ letter }}"&gt;
                &lt;div class="avatar"&gt;
                    &lt;span class="initials letter"&gt;{{ letter }}&lt;/span&gt;
                &lt;/div&gt;
            &lt;/span&gt;
        &lt;/li&gt;

        {% for profile in profiles %}
            &lt;li class="item"&gt;
                &lt;a href="{{ profile.url }}"&gt;&lt;h3&gt;{{ profile.title }}&lt;/h3&gt;&lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

<p>As you can see, I'd like to order the profiles by the custom field "profileLastname" and the groups by "profileAlphabet".</p>

<p>Any ideas?</p>

<templating><entries><group><order>
Order grouped entries
# Order grouped entries

(Asked by: username_0 on 2015-05-27)

I need to group and order member profiles alphabetically but I can't get it to work. Have a look here: http://ffsd.de.w0129b45.kasserver.com/mitglieder
(It's german but you should get the idea :))
In everything I tried either the groups are ordered correctly or the contents (profiles) of the group are… but never both. Here's the relevant code:
{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% for letter, profiles in allProfiles|group("profileAlphabet") %}
    
        
            
                
                    {{ letter }}
                
            
        

        {% for profile in profiles %}
            
                {{ profile.title }}
            
        {% endfor %}
    
{% endfor %}

As you can see, I'd like to order the profiles by the custom field "profileLastname" and the groups by "profileAlphabet".
Any ideas?

**Tags:** templating, entries, group, order

---

## 2 answers

### Answer by username_1 on 2015-05-27. Score: 5 | Accepted answer

The probably most easy way to do this is to sort the grouped array by key, which unfortunatelly is only possible with
a plugin, as Twig's sort filter only allows to sort by value.
Here I'm using Michael Rog's Supersort, but there are also other plugins that do this.
{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% set allProfilesGrouped = allProfiles|group("profileAlphabet")|supersort('ksort') %}


---

### Answer by username_2 on 2020-11-10. Score: 2

Stumbled upon this looking to answer similar problem. You should be able to do this now without a plugin, using the multisort filter where you iterate through your profiles, e.g.:
{% for profile in profiles|multisort(['profileLastname'],[SORT_ASC],[SORT_REGULAR]) %}


---

