[Resolved] help? – Custom SQL Query. How to ORDER BY two fields?
This is the custom select query that ALMOST works perfectly (taken from this thread http://wordpress.org/support/topic/121011?replies=11):
SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id) LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.term_id = 3 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = 'Event_Date' ORDER BY $wpdb->postmeta.meta_value ASC
^ this almost works for my purposes… but how can it be modified to ORDER BY 2 custom fields instead of just one?
I’ve got things setup so that every post in category 3 has an Event_Date custom field and an Event_Time custom field.
Right now it orders the post titles by the Event_Date.
I would like it to order also by Event_Time like this:
Also, how would I get it to only list the first 5 posts found instead of ALL posts?
- The topic ‘[Resolved] help? – Custom SQL Query. How to ORDER BY two fields?’ is closed to new replies.