Custom Select Query for Multiple Categories
-
I’m trying to create a query that would grab a post that exist in more than one category. (I’m making this custom because I’m pulling from the media library)
The two category ID I want to check is 18 and 19.
The current query I’m using:
SELECT wposts.* FROM $wpdb->posts wposts LEFT JOIN $wpdb->term_relationships ON (wposts.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 wposts.post_mime_type = 'image/jpeg' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN(18)
I want to add
AND $wpdb->term_taxonomy.term_id IN(19)
but that doesn’t work. I don’t work with sql, please help me WP heros!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Select Query for Multiple Categories’ is closed to new replies.