Ensure that 'hierarchical' is respected in `get_terms()` when multiple taxonomies are passed.

Previously, attempts to descend the family tree of each term were done using
the first taxonomy in the `$taxonomies` array, with the result that terms not
belonging to that taxonomy were not found and their children not properly
parsed. We fix this bug by fetching each term's taxonomy with the SQL query,
and then using that taxonomy to get the correct children for each term.

Fixes #31118.
Built from https://develop.svn.wordpress.org/trunk@31285


git-svn-id: http://core.svn.wordpress.org/trunk@31266 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-01-26 19:04:21 +00:00
parent af6e0f5c55
commit e199d2420f
2 changed files with 8 additions and 7 deletions

View File

@ -1887,10 +1887,10 @@ function get_terms( $taxonomies, $args = '' ) {
break; break;
case 'ids': case 'ids':
case 'id=>parent': case 'id=>parent':
$selects = array( 't.term_id', 'tt.parent', 'tt.count' ); $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' );
break; break;
case 'names': case 'names':
$selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name' ); $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' );
break; break;
case 'count': case 'count':
$orderby = ''; $orderby = '';
@ -1898,10 +1898,10 @@ function get_terms( $taxonomies, $args = '' ) {
$selects = array( 'COUNT(*)' ); $selects = array( 'COUNT(*)' );
break; break;
case 'id=>name': case 'id=>name':
$selects = array( 't.term_id', 't.name', 'tt.count' ); $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
break; break;
case 'id=>slug': case 'id=>slug':
$selects = array( 't.term_id', 't.slug', 'tt.count' ); $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
break; break;
} }
@ -1974,14 +1974,15 @@ function get_terms( $taxonomies, $args = '' ) {
_pad_term_counts( $terms, $_tax ); _pad_term_counts( $terms, $_tax );
} }
} }
// Make sure we show empty categories that have children. // Make sure we show empty categories that have children.
if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { if ( $hierarchical && $args['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, reset( $taxonomies ) ); $children = get_term_children( $term->term_id, $term->taxonomy );
if ( is_array( $children ) ) { if ( is_array( $children ) ) {
foreach ( $children as $child_id ) { foreach ( $children as $child_id ) {
$child = get_term( $child_id, reset( $taxonomies ) ); $child = get_term( $child_id, $term->taxonomy );
if ( $child->count ) { if ( $child->count ) {
continue 2; continue 2;
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31284'; $wp_version = '4.2-alpha-31285';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.