I have several custom post types, each with one or more custom taxonomies. I'd like to add a filter for each taxonomy to the relevant custom post type edit screen, but my solution is not working.
The problem
First off, I know why the query is failing, but I don't know what is causing the query to be constructed in this manner.
When I inspect the $wp_global
query after filtering a post type I notice that the condition AND (1=0)
exists, whcih of course is never going to be true.
My (broken) solution
To output the various filters I use a class which can be found in this Pastebin.
To initiate the Class I'm using this code (trimmed down here for just one post type and taxonomy, whcih I will refer to for ease during the rest of this question) -
add_action('init', 'fgw_filter_taxonomies');
function fgw_filter_taxonomies(){
new FGW_CPT_Taxonomy_Filter(
array('file' => array('file_type'))
);
}
The filters are displayed perfectly, however when using any of them WP returns no results.
My investigation
I have studied the resultant $wp_query
global and I notice that WP is actually adding [file_type] => 22
to the query
and query_var
arrays, and the tax_query
array appears to be created correctly.
However, as previously mentioned, WP is for some reason constructing the query incorrectly, meaning that no results are found.
[tax_query] => WP_Tax_Query Object
(
[queries] => Array
(
[0] => Array
(
[taxonomy] => file_type
[terms] => Array
(
[0] => 22
)
[field] => slug
[operator] => IN
[include_children] => 1
)
)
[relation] => AND
[table_aliases:protected] => Array
(
)
[queried_terms] => Array
(
[file_type] => Array
(
[terms] => Array
(
[0] => 22
)
[field] => slug
)
)
[primary_table] => fgw_posts
[primary_id_column] => ID
)
My question
What next? Where can I look to fix this problem? I've trawled through query.php
, but I'm nore really sure what I'm looking for.
I'm genuinly stumped by this behaviour, particularly as comparing the resultant $wp_query
global to that generated when filtering the builtin category
or post_tag
texonomy seems identical (other than the name of the taxonomy of course).