WordPress.org

Make WordPress Core

Opened 4 months ago

#52904 new defect (bug)

WP_Term_Query does not return deeper descendants of child_of when direct children of child_of are not part of the results

Reported by: xParham Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version:
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:

Description

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.

Change History (0)

Note: See TracTickets for help on using tickets.