Custom query for multiple categories
-
I use this code from Codex:
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.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id = 27 AND $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = 'house_price' ORDER BY $wpdb->postmeta.meta_value ASC
But I need to modify it for selecting posts which are in two different categories. I tried this:
AND $wpdb->term_taxonomy.term_id IN (27,28)
But this selects posts which are in category 27 OR in category 28. And I need to select posts which are in category 27 AND also in category 28. These examples does not work for me:
AND $wpdb->term_taxonomy.term_id = 27,28
or this:
AND $wpdb->term_taxonomy.term_id = 27 AND $wpdb->term_taxonomy.term_id = 28
All return “No posts found” But I know about posts which are in category 27 and also in category 28.Thank you for your help…
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Custom query for multiple categories’ is closed to new replies.