Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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! :)

share|improve this question
    
It'd probably be better to use get_posts() instead of WP_Query() -- wordpress.stackexchange.com/questions/1753/… –  Ian Dunn Feb 12 '12 at 17:01
add comment

3 Answers

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?

share|improve this answer
add comment

This is untested, but you can try this query

"SELECT post_title FROM wp_posts ORDER BY IF(LEFT(post_title,2)="A ",SUBSTRING(post_title FROM 3),IF(LEFT(post_title,3)="An ",SUBSTRING(post_title FROM 4),IF(LEFT(post_title,4)="The ",SUBSTRING(post_title FROM 5),post_title)))"

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.

share|improve this answer
    
I'm sorry, my bad, I wasn't specific enough, I meant if there was a way to do it inside Wordpress queries :s (I edited to clarify now). –  Alekz Feb 8 '12 at 23:52
    
Now that I think about it, maybe the quick, SEO unfriendly and dirty solution would be having a Custom Field with the complete title and showing it if it exists... or vice versa, and finding a way to order by the Custom Field :/ Thank you for the query, it is most helpful, it will come in handy in the future for me! :) –  Alekz Feb 9 '12 at 3:21
    
You can make custom queries with the WordPress API using $wpdb->query(). –  Ian Dunn Feb 12 '12 at 17:03
add comment

$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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.