I currently have episodes from a TV Show that feature bands playing, so for example I have:
- Moby
- The Dandy Warhols
- The Kooks
My wp_query looks like this:
$loop = new WP_Query(array('post_type' => 'episodio', 'cat' => '9', 'posts_per_page' => 90, 'orderby' => 'title','order' => 'ASC' ));
But I want to order them like this, alphabetically, without taking into account ‘the’:
- The Dandy Warhols
- The Kooks
- Moby
There are a lot of records in the database, so it’s not very practical and/or efficient to get everything into an array, remove ‘the’, order again and then going through the array to display the data.
Is this possible in WP_Query? Maybe through a filter?
Thanks a lot in advance! 🙂
If you’re using the plugin SEO Ultimate (it’s popular and I recommend using it), it has a component called Slug Optimizer that strips those types of words out of the post-slug, so if the post title is “The Dandy Warhols”, the slug would just be “dandy-warhols”.
Perhaps just order by the post-slug?
This is untested, but you can try this query
It’s not the most efficient, but it should get the job done.
The quickest way would probably be to have an additional column for the posts with these certain words stripped, solely for the sorting.
$loop = new WP_Query(array(‘post_type’ => ‘episodio’, ‘cat’ => ‘9’, ‘posts_per_page’ => 90, ‘orderby’ => ‘title’,’order’ => ‘DESC’ ));
This will get the post title descending from category id 9