Opened 6 years ago
Last modified 6 years ago
#45457 new defect (bug)
get_terms returns incorrect terms set for indirect children
Reported by: | mh35 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.9.8 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
I created categories as below.
未分類(term_id=1) has two children, C1(term_id=2) and C2(term_id=3).
C1 has three children, C3(term_id=4), C4(term_id=5) and C5(term_id=6).
C2 has two children, C6(term_id=7) and C7(term_id=8).
If I query as below, it returns correct answer.
<?php get_terms(array('taxonomy' => 'category', 'hide_empty' => false, 'name' => 'C1', 'child_of' => 1));
This query returns C1 term.
But I query as below, it returns no terms. I think this behavior is incorrect.
<?php get_terms(array('taxonomy' => 'category', 'hide_empty' => false, 'name' => 'C4', 'child_of' => 1));
Attachments (1)
Change History (4)
This ticket was mentioned in Slack in #core by mh35. View the logs.
6 years ago
#2
@
6 years ago
As it states in the parameter definitions on https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
'child_of' (int) Term ID to retrieve child terms of. If multiple taxonomies are passed, $child_of is ignored. Default 0.
So it looks like the correct result to me.
#3
@
6 years ago
If I pass only taxonomy and child_of parameter, this function returns direct and indirect children.
<?php get_terms(array('taxonomy' => 'category', 'hide_empty' => false, 'child_of' => 1));
This returns C1, C3, C4, C5, C2, C6 and C7. If I want to get only direct children, I pass parent parameter.
<?php get_terms(array('taxonomy' => 'category', 'hide_empty' => false, 'parent' => 1));
This returns C1 and C2.
Bug cause situation