0

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?

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
| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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