From 47742eae129d6c4a8e7df0aabb7965beb96598f4 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 30 Oct 2014 02:12:22 +0000 Subject: [PATCH] In `get_terms()`, do not override 'hierarchical' and 'pad_counts' when 'parent' is present. The previous behavior resulted in descendant terms being improperly excluded from the results when passing a 'parent', even when 'hierarchical' had been set to true. The patch also adds unit tests that demonstrate the various interactions between the 'child_of', 'parent', and 'hierarchical' parameters of `get_terms()`. Props landakram. Fixes #29815. Built from https://develop.svn.wordpress.org/trunk@30107 git-svn-id: http://core.svn.wordpress.org/trunk@30107 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index cd36bec16f..d8abfc00fa 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1628,13 +1628,19 @@ function get_terms( $taxonomies, $args = '' ) { $args = wp_parse_args( $args, $defaults ); $args['number'] = absint( $args['number'] ); $args['offset'] = absint( $args['offset'] ); - if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) || - ( '' !== $args['parent'] && 0 !== $args['parent'] ) ) { - $args['child_of'] = 0; + + // Save queries by not crawling the tree in the case of multiple taxes or a flat tax. + if ( ! $single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ) { + $args['child_of'] = false; $args['hierarchical'] = false; $args['pad_counts'] = false; } + // 'parent' overrides 'child_of'. + if ( 0 < intval( $args['parent'] ) ) { + $args['child_of'] = false; + } + if ( 'all' == $args['get'] ) { $args['child_of'] = 0; $args['hide_empty'] = 0; diff --git a/wp-includes/version.php b/wp-includes/version.php index 8962afb2c1..5c54f7f5b0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30106'; +$wp_version = '4.1-alpha-30107'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.