[wp-trac] [WordPress Trac] #20493: WP_Tax_Query->clean_query removes taxonomy term being searched for
WordPress Trac
wp-trac at lists.automattic.com
Thu Apr 19 23:53:40 UTC 2012
#20493: WP_Tax_Query->clean_query removes taxonomy term being searched for
--------------------------+-----------------------------
Reporter: israelshirk | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
--------------------------+-----------------------------
When querying using a tax_query on a hierarchical taxonomy,
WP_Tax_Query->clean_query() removes the term ID passed in.
So if I have a taxonomy which is structured like this:
{{{
Australia
--Sydney
----East Sydney
----West Sydney
----Whatever else
}}}
And objects which are tagged with East, West, and then some are just
Sydney.
Now in the parse_query filter we do something like this to include objects
tagged as Sydney and its children:
{{{
$terms = $state->term_id;
$tax_query[] = Array(
'taxonomy' => 'location',
'field' => 'id',
'terms' => Array($term)
);
$wp_query->set("tax_query", $tax_query);
}}}
When clean_query runs through the query, it will remove the term_id for
Sydney and replace it with the IDs for East Sydney, West Sydney, and the
rest of Sydney's children. This results in any objects only tagged with
Sydney not being returned by the query.
Changing line 736 of wp-includes/taxonomy.php from:
{{{
$query['terms'] = $children;
}}}
to:
{{{
$query['terms'] = array_merge($query['terms'], $children);
}}}
makes it behave as expected.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20493>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list