Order entries, exclude 'the' from order criteria 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 )') %}
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 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.