TransWikia.com

orderBy title, but remove the word "The" from titles

Craft CMS Asked on September 4, 2021

If I have a huge list of TV shows and Movies, many of them have "The" in the title, meaning they all get grouped together if you order by title.

Is it possible to "filter out" a word in entry titles when using orderBy?

{% set entries = craft.entries().section('media').orderby('title asc').limit(24).all() %}

One Answer

{% set entries = craft.entries().section('media').orderBy("(CASE WHEN `title` LIKE 'The %' THEN SUBSTRING(`title`, 5) WHEN `title` LIKE 'A %' THEN SUBSTRING(`title`, 3) ELSE `title` END) asc").limit(24).all() %} worked.

Answered by MarkD on September 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP