In `get_terms()`, leverage `get_term_children()` over `_get_term_children()` when making sure to show empty terms that have children in a hierarchical taxonomy while avoiding duplicates.
Adds unit test for `child_of` param. Adjusts unit tests for `get_terms()`. See [27108] and [27125]. Props SergeyBiryukov. Fixes #27123. Built from https://develop.svn.wordpress.org/trunk@27458 git-svn-id: http://core.svn.wordpress.org/trunk@27304 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3556e565b3
commit
c353fa41a2
|
@ -1477,11 +1477,15 @@ function get_terms($taxonomies, $args = '') {
|
||||||
if ( $hierarchical && $hide_empty && is_array( $terms ) ) {
|
if ( $hierarchical && $hide_empty && is_array( $terms ) ) {
|
||||||
foreach ( $terms as $k => $term ) {
|
foreach ( $terms as $k => $term ) {
|
||||||
if ( ! $term->count ) {
|
if ( ! $term->count ) {
|
||||||
$children = _get_term_children( $term->term_id, $terms, reset( $taxonomies ) );
|
$children = get_term_children( $term->term_id, reset( $taxonomies ) );
|
||||||
if ( is_array( $children ) )
|
if ( is_array( $children ) ) {
|
||||||
foreach ( $children as $child )
|
foreach ( $children as $child_id ) {
|
||||||
if ( $child->count )
|
$child = get_term( $child_id, reset( $taxonomies ) );
|
||||||
|
if ( $child->count ) {
|
||||||
continue 2;
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// It really is empty
|
// It really is empty
|
||||||
unset($terms[$k]);
|
unset($terms[$k]);
|
||||||
|
@ -2923,20 +2927,6 @@ function _get_term_children($term_id, $terms, $taxonomy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $term->term_id == $term_id ) {
|
if ( $term->term_id == $term_id ) {
|
||||||
if ( isset( $has_children[$term_id] ) ) {
|
|
||||||
$current_id = $term_id;
|
|
||||||
while ( $current_id > 0 ) {
|
|
||||||
foreach ( $has_children[$current_id] as $t_id ) {
|
|
||||||
if ( $use_id ) {
|
|
||||||
$term_list[] = $t_id;
|
|
||||||
} else {
|
|
||||||
$term_list[] = get_term( $t_id, $taxonomy );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$current_id = isset( $has_children[$t_id] ) ? $t_id : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue