<p>I've seen that before, if you look at the <code>sites</code> table in your DB, you'll see that a few sites might have their <code>sortOrder</code> set to 1. </p>

<p>If you go to Settings → Sites → [the offending group] in your Control Panel, try to reset the order of your sites in there (drag/drop using the little handle to the right of each site row), it should stop them showing up in a random order on the front end.</p>

CC BY-SA 4.0
2019-05-31T08:58:18.963Z
Oliver, you hero! You are 100% correct, it was that these 10 sites all had sortOrder 1
John Stevens
CC BY-SA 4.0
2019-05-31T08:14:26.340Z
2019-05-31T08:14:26.340Z
Oli
<p>We have 38 sites running, divided over 6 groups.
But for some weird reason on showing the sites list, 10 sites are showing up random. How can we fix this, or how can we order the sites on 'name' or 'id'?</p>

<pre><code>{% set sites = craft.app.sites.allsites() %}
{% for site in sites %}
    {{ site.name }}&lt;br&gt;
{% endfor %}
</code></pre>

<p><a href="https://i.sstatic.net/qwYvF.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qwYvF.gif" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-05-30T16:11:35.483Z
Huh... looks like it's ordered by Site Group name ascending first, then Site sort order ascending second. Not real sure why that would change in between page refreshes. 
 https://github.com/craftcms/cms/blob/develop/src/services/Sites.php#L1214
Brad Bell
CC BY-SA 4.0
2019-05-31T06:26:10.327Z
and .order() is not working on this either?
John Stevens
<craft3><multi-site><ordering>
How to order Sites
# How to order Sites

(Asked by: username_0 on 2019-05-30)

We have 38 sites running, divided over 6 groups.
But for some weird reason on showing the sites list, 10 sites are showing up random. How can we fix this, or how can we order the sites on 'name' or 'id'?
{% set sites = craft.app.sites.allsites() %}
{% for site in sites %}
    {{ site.name }}
{% endfor %}

**Tags:** craft3, multi-site, ordering
> **Comments:**
> **username_1**: Huh... looks like it's ordered by Site Group name ascending first, then Site sort order ascending second. Not real sure why that would change in between page refreshes.   https://github.com/craftcms/cms/blob/develop/src/services/Sites.php#L1214  
> **username_0**: and .order() is not working on this either?  

---

## 1 answers

### Answer by username_2 on 2019-05-31. Score: 5 | Accepted answer

I've seen that before, if you look at the `sites` table in your DB, you'll see that a few sites might have their `sortOrder` set to 1.

If you go to Settings → Sites → [the offending group] in your Control Panel, try to reset the order of your sites in there (drag/drop using the little handle to the right of each site row), it should stop them showing up in a random order on the front end.

> **Comments:**
> **username_0**: Oliver, you hero! You are 100% correct, it was that these 10 sites all had sortOrder 1  

---

