[wp-trac] [WordPress Trac] #52904: WP_Term_Query does not return deeper descendants of child_of when direct children of child_of are not part of the results
WordPress Trac
noreply at wordpress.org
Wed Mar 24 22:38:31 UTC 2021
#52904: WP_Term_Query does not return deeper descendants of child_of when direct
children of child_of are not part of the results
--------------------------+-----------------------------
Reporter: xParham | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: major | Keywords: needs-patch
Focuses: |
--------------------------+-----------------------------
Let's say for the hierarchical taxonomy `mytax` we have the following
terms and term ids(in parentheses):
{{{
- A (1)
-- AB (2)
--- ABC (3)
- B (4)
-- BD (5)
-- ABC (6)
}}}
The following query works fine and it returns both terms with ID 2 and 3
{{{
print_r(
get_terms(
[
'taxonomy' => 'mytax',
'name__like' => 'AB',
'child_of' => 1,
'hide_empty' => false
]
)
);
}}}
However, the following query returns an empty array (since term_id=2 will
no longer be in the results):
{{{
print_r(
get_terms(
[
'taxonomy' => 'mytax',
'name__like' => 'ABC',
'child_of' => 1,
'hide_empty' => false
]
)
);
}}}
but it is expected that it returns the term ABC with term_id=3.
This seems to be a bug with the logic in `_get_term_children()` where if
direct children of the asking ancestor are not within the initial set of
the terms, the recursion will never happen and deeper descendants are then
removed from the query results.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52904>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list