I’m using a custom query to pull some posts from a custom post type. I’m having problems with it so I used print_r on my WP_Query object and I found something strange.
my query has these arguments:
'post_type' => 'event'
,'tax_query' => array(
array(
'taxonomy' => 'event-categories'
,'field' => 'id'
,'terms' => 72
,'operator' => 'IN'
)
)
,'order' => 'ASC'
);
$query = new WP_Query( $args );
and when I remove the tax_query portion I get all my posts, but when I include it I get none. I’m positive I have more than one post with the taxonomy ID of 72. When I look at my print_r($query) with the post type in, I see this:
WP_Query Object
(
[query_vars] => Array
(
[post_type] => Array
(
[0] => media_player
[1] => ada_slides
[2] => closings
[3] => staff
[4] => post
[5] => page
)
All of my post types are listed except for the one I wanted, event. If I take out tax_query from my args, it looks like this:
WP_Query Object
(
[query_vars] => Array
(
[post_type] => event
[order] => ASC
…and so on
Also, if I change my operator to NOT IN, it searches the correct post type but excludes the category I want to search for.
Why would using a tax_query argument seemingly invalidate my post_type argument and instead include all post types but the one I wanted?
Turned out to be a plugin conflict. I had turned off all plugins at one point to no noticeable benefit, but then turned a few back on so I could run some other things on the site I was working with.
The trouble was with the Easy Custom Content Types plugin (a very handy plugin) and I’m checking in with the developer of it. It looks like I may not have the latest version of it either so maybe he’s already fixed it.