WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've successfully sorted my custom post type "property" based on it's city and state using this:

$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->postmeta wpostmeta2
WHERE wposts.ID = wpostmeta.post_id
AND wposts.ID = wpostmeta2.post_id
AND wpostmeta.meta_key = 'state'
AND wpostmeta2.meta_key = 'city'
AND wposts.post_type = 'property'
AND wposts.post_status = 'publish'
ORDER BY wpostmeta.meta_value ASC, wpostmeta2.meta_value ASC
";$pageposts = $wpdb->get_results($querystr, OBJECT);?>

Now I'd like to add a third sorter, which would just be the post title (the name of the property). How can I add this in? What is the proper name for identifying the post title as part of the query string?

share|improve this question



and you will see that's post_title then in your order part of the query you will refer to

share|improve this answer
Thank you -- wposts.post_title did the trick (you forgot the "s" in wposts) – ShawnB Oct 27 '11 at 14:21

Your Answer


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.