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.

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

<?php
$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

1 Answer 1

Check:

http://codex.wordpress.org/Database_Description

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

wpost.post_title
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

 
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.