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
This commit is contained in:
Boone Gorges 2014-10-30 02:12:22 +00:00
parent 3dcf418545
commit 47742eae12
2 changed files with 10 additions and 4 deletions

View File

@ -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;

View File

@ -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.