Opened 3 years ago
Closed 3 years ago
#55887 closed defect (bug) (duplicate)
Calling get_terms() with exact same args (most important is exclude_tree) returns unexpected results from runtime cache (second call)
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.0 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
Calling get_terms() with exact same args (most important is exclude_tree) returns unexpected results from runtime cache (second call).
Test case:
- Create some terms ex. in category tax
->Bez kategorii
->A (term_id: 110)
-->A1
->B (term_id: 111)
-->B1
->C (term_id: 112)
-->C1
- Then call get_terms() two times:
echo 'exclude B tree<br>'; var_dump(get_terms(array('taxonomy' => 'category', 'exclude_tree' => array(111), 'hide_empty' => false, 'fields' => 'names'))); echo '<br>2 exclude B tree<br>'; var_dump(get_terms(array('taxonomy' => 'category', 'exclude_tree' => array(111), 'hide_empty' => false, 'fields' => 'names')));
results:
exclude B tree array(5) { [0]=> string(1) "A" [1]=> string(2) "A1" [2]=> string(13) "Bez kategorii" [3]=> string(1) "C" [4]=> string(2) "C1" } 2 exclude B tree array(0) { }
Change History (3)
#2
@
3 years ago
One more test case:
echo 'exclude_tree B (111)<br>'; var_dump(get_terms(array('taxonomy' => 'category', 'exclude_tree' => 111, 'hide_empty' => 0, 'fields' => 'ids'))); echo '<br><br>child_of B (111)<br>'; var_dump(get_terms(array('taxonomy' => 'category', 'child_of' => 111, 'hide_empty' => 0, 'fields' => 'ids')));
result
exclude_tree B (111) array(5) { [0]=> int(110) [1]=> int(113) [2]=> int(1) [3]=> int(112) [4]=> int(115) } OK child_of B (111) array(7) { [0]=> int(110) [1]=> int(113) [2]=> int(111) [3]=> int(114) [4]=> int(1) [5]=> int(112) [6]=> int(115) } WRONG
Second get_terms() results all terms not those which are children of parent term_id = 111.
Note: See
TracTickets for help on using
tickets.
After some tests on WP_Term_Query::get_terms(), this query
does the following, first calls another get_terms() to fill $exclusions
and I think here's the problem, adding some output before
in WP_Term_Query::get_terms() I got these results:
in $cache_args you can see that child_of = 111 so this query should return children for term_id = 111 and it does return proper result which is $term_objects but this is not what is being added to cache, $terms var is, as you can see $terms stores result of $wpdb->get_results( $this->request ); which is result of
that is all (7) terms in this taxonomy, $term_objects is the right list of terms limited to specific parent (child_of = 111).
Calling same get_terms() as previously second time results exclusion of all (7) terms (result from cache).