Answers.Body: <p>Just a little tweak, and double quotes needed around the thing it is LIKE.</p>
  
  <pre><code>{% for entry in craft.entries.section('hotels').order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 3) ELSE title END ) asc') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-08T15:57:27.630Z
Answers.LastActivityDate: 2017-02-08T15:57:27.630Z
Answers.UserDisplayName: 4midori
Answers.Body: <p>Completely untested, but try something like this:</p>
  
  <pre><code>{% for entry in craft.entries.section('hotels').order('(CASE WHEN title LIKE 'The %' THEN SUBSTRING(title, 4) ELSE title END )') %}
  </code></pre>
  
  <p>MySQL's <a href="https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_ltrim" rel="nofollow noreferrer">LTRIM</a> isn't what you want because that just removes leading spaces.  <code>SUBSTRING</code> should do it, though.</p>
  
  <p>Also, keep in mind this is a MySQL specific query.  If you ever planning on running on PostgreSQL (that the Craft 3 beta supports), it would have to be adjusted.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-07T03:12:44.043Z
Answers.Text: Now I get  `Arguments must be separated by a comma. Unexpected token "name" of value "The" ("punctuation" expected with value ",").` Can I pull all the entries into an array and use Twig to filter? If so, is there an example available? Thanks.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-06T19:54:53.793Z
Answers.LastActivityDate: 2017-02-06T19:54:53.793Z
Answers.UserDisplayName: Brad Bell
Body: <p>I know this is partly a Twig question, but I've poked around quite a bit here, in Twig docs, Craft docs, and cannot find the right syntax.</p>
  
  <p>I have a bunch of entries with titles like:</p>
  
  <ul>
  <li>Hotel A</li>
  <li>Grand Hotel B</li>
  <li>Zither Hotel Grand Plaza</li>
  <li>The Top Hotel</li>
  </ul>
  
  <p>I want to order by title, alphabetical, but I need to exclude leading 'The ' from the order. I've tried this, but it barfs.</p>
  
  <pre><code> {% for entry in craft.entries.section('hotels').order('(CASE when title LIKE 
  '%The ' THEN LTRIM(title, 4) ELSE title END )') %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-05T00:34:32.243Z
Comments.Text: How does it barf?  Is there an error message?  Also, pretty sure the LIKE should be `'The %'`, since you want to it start with `The ` and match anything after it.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-06T16:46:12.443Z
Comments.Text: I get  
  
  `Arguments must be separated by a comma. Unexpected token "string" of value " THEN LTRIM(title, 4) ELSE title END )" ("punctuation" expected with value ","). `
Comments.UserDisplayName: 4midori
Tags: <templating><ordering><mysql>
Title: Order entries, exclude 'the' from order criteria
ThreadText: # Order entries, exclude 'the' from order criteria
  
  (Asked by: username_0 on 2017-02-03)
  
  I know this is partly a Twig question, but I've poked around quite a bit here, in Twig docs, Craft docs, and cannot find the right syntax.
  
  I have a bunch of entries with titles like:
  
  * Hotel A
  * Grand Hotel B
  * Zither Hotel Grand Plaza
  * The Top Hotel
  
  I want to order by title, alphabetical, but I need to exclude leading 'The ' from the order. I've tried this, but it barfs.
  
  ```
   {% for entry in craft.entries.section('hotels').order('(CASE when title LIKE 
  '%The ' THEN LTRIM(title, 4) ELSE title END )') %}
  
  ```
  
  **Tags:** templating, ordering, mysql
  
  > **Comments:**
  > **username_1**: How does it barf?  Is there an error message?  Also, pretty sure the LIKE should be `'The %'`, since you want to it start with `The ` and match anything after it.  
  > **username_0**: I get    `Arguments must be separated by a comma. Unexpected token "string" of value " THEN LTRIM(title, 4) ELSE title END )" ("punctuation" expected with value ","). `  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-02-08. Score: 1 | Accepted answer
  
  Just a little tweak, and double quotes needed around the thing it is LIKE.
  
  ```
  {% for entry in craft.entries.section('hotels').order('(CASE WHEN title LIKE "The %" THEN SUBSTRING(title, 3) ELSE title END ) asc') %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2017-02-06. Score: 2
  
  Completely untested, but try something like this:
  
  ```
  {% for entry in craft.entries.section('hotels').order('(CASE WHEN title LIKE 'The %' THEN SUBSTRING(title, 4) ELSE title END )') %}
  
  ```
  
  MySQL's [LTRIM](https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_ltrim) isn't what you want because that just removes leading spaces. `SUBSTRING` should do it, though.
  
  Also, keep in mind this is a MySQL specific query. If you ever planning on running on PostgreSQL (that the Craft 3 beta supports), it would have to be adjusted.
  
  > **Comments:**
  > **username_0**: Now I get  `Arguments must be separated by a comma. Unexpected token "name" of value "The" ("punctuation" expected with value ",").` Can I pull all the entries into an array and use Twig to filter? If so, is there an example available? Thanks.  
  
  ---
  
  