From e199d2420fd628b8f558cabcaed79b9eb39ecaa6 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 26 Jan 2015 19:04:21 +0000 Subject: [PATCH] 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 --- wp-includes/taxonomy.php | 13 +++++++------ wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 0419e97424..16bdf26ae8 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1887,10 +1887,10 @@ function get_terms( $taxonomies, $args = '' ) { break; case 'ids': case 'id=>parent': - $selects = array( 't.term_id', 'tt.parent', 'tt.count' ); + $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' ); break; 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; case 'count': $orderby = ''; @@ -1898,10 +1898,10 @@ function get_terms( $taxonomies, $args = '' ) { $selects = array( 'COUNT(*)' ); break; case 'id=>name': - $selects = array( 't.term_id', 't.name', 'tt.count' ); + $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' ); break; case 'id=>slug': - $selects = array( 't.term_id', 't.slug', 'tt.count' ); + $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' ); break; } @@ -1974,14 +1974,15 @@ function get_terms( $taxonomies, $args = '' ) { _pad_term_counts( $terms, $_tax ); } } + // Make sure we show empty categories that have children. if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { foreach ( $terms as $k => $term ) { 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 ) ) { foreach ( $children as $child_id ) { - $child = get_term( $child_id, reset( $taxonomies ) ); + $child = get_term( $child_id, $term->taxonomy ); if ( $child->count ) { continue 2; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 9dc910d9a3..9c9e32a7fa 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.