Custom Fields Select Query – multiple fields, plus category
-
I’m using the code below to select posts from a particular category that matches a chosen custom field key and value. I’m trying to figure out how I can change the code so that it selects posts that match a particular category, as well as multiple chosen custom field keys and values.
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 = 2 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = 'gametype' AND $wpdb->postmeta.meta_value= '$gametype' ORDER BY $wpdb->postmeta.meta_value ASC
Any help would be greatly appreciated.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Custom Fields Select Query – multiple fields, plus category’ is closed to new replies.