• I’m trying to put together a directory and would like a way to query my posts based on the first letter. I’m guessing I need to use query_posts(). Here is a base SQL snippet:

    name = 'A%'

    In other words I just want to return posts that begin on the letter “A”. I could just return everything then use javascript to create and dynamically sort the whole list, but that gets really long and will no doubt tax the webserver and database. Is there another way around this so I can query posts that begin on a certain letter?

    Thanks!

Viewing 1 replies (of 1 total)
  • As far as I’m aware, no. You can’t directly query using parameters like that. You could use the $wpdb class to select post IDs where name LIKE ‘a%’ and then use query_posts with the 'post__in' => array(...IDs...) parameter to get the rest of the data. You might be better off just using $wpdb to grab it all in one go– depends on what information need from the query I guess.

Viewing 1 replies (of 1 total)
  • The topic ‘How to query by post name first letter’ is closed to new replies.