<p>The group filter loops through the passed elements in the order that they are returned by your query and builds the groups array in the order that it encounters the values being grouped. So there’s no predictable way to control what order the array keys are ordered. </p>

<p>If you want to loop through all entries by dealStatus in a fixed order you could replace your <code>for</code> loop with:</p>

<pre><code>{% for status in [‘InMarket’,’postBid’,’closing’,’closed’] %}
    {% if allDealsByStatus[status] is defined %}

        {% set entriesInStatus = allDealsByStatus[status] %}

        {# your list output code here #}

    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2018-04-08T19:17:42.380Z
2018-04-08T19:17:42.380Z
Steve Rowling
<p>I have a channel of entries that are being pulled into a single. I then  want to group the entries by a dropdown field called dealStatus.</p>

<p>This is working correctly, however the grouping is not outputting the order correctly. I expect the order of the groups to be in the same order that the dropdown field has them.</p>

<p>InMarket
postBid
closing
closed</p>

<p>Instead the groups are getting output in this order</p>

<p>postBid
inMarket
closing
closed</p>

<p>How do I get the groups ordered the same as the dropdown field option order?</p>

<p>My current code:</p>

<pre><code>{% set allDeals = craft.entries.section('deals').relatedTo(entry) %}
{% set allDealsByStatus = allDeals|group('dealStatus') %}

{% for status, entriesInStatus in allDealsByStatus %}
    &lt;li class="accordion-item {% if loop.index =="1" %}is-active{% endif %}" data-accordion-item&gt;
      &lt;!-- Accordion tab title --&gt;
      &lt;a href="#" class="accordion-title"&gt;
      {{ status }}
      &lt;i class="arrow right"&gt;&lt;/i&gt;&lt;!-- /.arrow right --&gt;
      &lt;/a&gt;

      &lt;!-- Accordion tab content: it would start in the open state due to using the `is-active` state class. --&gt;
      &lt;div class="accordion-content" data-tab-content&gt;
        &lt;ul class="no-bullet market-content"&gt;
          {% for entry in entriesInStatus %}
            &lt;li&gt;
              &lt;a href=""&gt;
                &lt;img src="http://via.placeholder.com/120x60/eaeaea?text=logo here" alt="" class="market-logo"&gt;

                &lt;p&gt;{{ entry.title }}&lt;/p&gt;

                &lt;img src="/assets/img/next.svg" alt="" class="go-icon"&gt;
              &lt;/a&gt;
            &lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;&lt;!-- /.no-bullet --&gt;
      &lt;/div&gt;
    &lt;/li&gt;
{% endfor %}
</code></pre>

<p>This is on Craft 3.0.1</p>

<templating><craft3><group>
Grouping by select - keep order of options
# Grouping by select - keep order of options

(Asked by: username_0 on 2018-04-06)

I have a channel of entries that are being pulled into a single. I then  want to group the entries by a dropdown field called dealStatus.
This is working correctly, however the grouping is not outputting the order correctly. I expect the order of the groups to be in the same order that the dropdown field has them.
InMarket
postBid
closing
closed
Instead the groups are getting output in this order
postBid
inMarket
closing
closed
How do I get the groups ordered the same as the dropdown field option order?
My current code:
{% set allDeals = craft.entries.section('deals').relatedTo(entry) %}
{% set allDealsByStatus = allDeals|group('dealStatus') %}

{% for status, entriesInStatus in allDealsByStatus %}
    
      
      
      {{ status }}
      
      

      
      
        
          {% for entry in entriesInStatus %}
            
              
                

                {{ entry.title }}

                
              
            
          {% endfor %}
        
      
    
{% endfor %}

This is on Craft 3.0.1

**Tags:** templating, craft3, group

---

## 1 answers

### Answer by username_1 on 2018-04-08. Score: 1 | Accepted answer

The group filter loops through the passed elements in the order that they are returned by your query and builds the groups array in the order that it encounters the values being grouped. So there’s no predictable way to control what order the array keys are ordered. 
If you want to loop through all entries by dealStatus in a fixed order you could replace your for loop with:
{% for status in [‘InMarket’,’postBid’,’closing’,’closed’] %}
    {% if allDealsByStatus[status] is defined %}

        {% set entriesInStatus = allDealsByStatus[status] %}

        {# your list output code here #}

    {% endif %}
{% endfor %}


---

