<p>According to <a href="https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substr" rel="nofollow noreferrer">SUBSTRING</a>, the first character starts at 1.  So if you wanted to start at the position immediate after <code>The</code> (with one space), you'd need to start at position 5.</p>

<p>Just did a test locally and it works as expected for me if I use:</p>

<pre><code>.order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 5) ELSE title END ) asc')
</code></pre>

CC BY-SA 3.0
2017-07-17T22:52:45.950Z
2017-07-17T22:52:45.950Z
Brad Bell
<p>I need to list the names of all of my entries in alphabetical order excluding 'the' (which could only be at the beginning). I've looked around online, but I was only able to find a code segment (which I've modified to fit my needs). However, it's still incorrectly sorting them as you can see in the attached image.</p>

<p>Current code:</p>

<pre><code>{% for entry in craft.entries.section('partners').featuredMediaPartner('1').order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 3) ELSE title END ) asc') %}
</code></pre>

<p>Please help me fix this issue, thanks.</p>

<p><a href="https://i.sstatic.net/29mC9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/29mC9.png" alt="Entries not being correctly sorted"></a></p>

<entries><forloop><ordering><sorting><order>
Sort entry titles alphabetically excluding 'The'?
# Sort entry titles alphabetically excluding 'The'?

(Asked by: username_0 on 2017-07-17)

I need to list the names of all of my entries in alphabetical order excluding 'the' (which could only be at the beginning). I've looked around online, but I was only able to find a code segment (which I've modified to fit my needs). However, it's still incorrectly sorting them as you can see in the attached image.
Current code:
{% for entry in craft.entries.section('partners').featuredMediaPartner('1').order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 3) ELSE title END ) asc') %}

Please help me fix this issue, thanks.

**Tags:** entries, forloop, ordering, sorting, order


---

## 1 answers

### Answer by username_1 on 2017-07-17. Score: 3

According to SUBSTRING, the first character starts at 1.  So if you wanted to start at the position immediate after The (with one space), you'd need to start at position 5.
Just did a test locally and it works as expected for me if I use:
.order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 5) ELSE title END ) asc')


---

