WP_Query only returns posts that match first term in tax_query array
-
I’m trying to query some custom post types based on terms from a custom taxonomy. The arguments I’m putting into WP_Query are:
Array ( [post_type] => Array ( [0] => event ) [post_status] => publish [posts_per_page] => -1 [orderby] => title [order] => ASC [tax_query] => Array ( [0] => Array ( [taxonomy] => event-type [field] => slug [operator] => IN [terms] => Array ( [0] => walk [1] => talk [2] => workshop ) ) ) )
But all I’m getting back are posts with the ‘walk’ term. If I change the order of the tax_query array I find that it always appears to be the first term in the array.
The SQL this translates into is:
SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (32,33,34)) AND wp_posts.post_type = 'event' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title ASC
I can’t see what’s wrong with this code but it’s been bugging me for a while now.
The argument array is actually built using shortcode attributes, but the above code is what is generated and passed to WP_Query.
Any idea what’s going on here?
thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP_Query only returns posts that match first term in tax_query array’ is closed to new replies.