Don't force child_of=0 for non-hierarchical taxonomies in get_terms().

This forcing appears to have been introduced to save unnecessary queries, but
(a) in some cases it appeared to be causing *more* queries, and (b) it caused
incorrect results when the 'exclude_tree' param of `get_terms()` called
`get_terms()` on each item in the tree using the 'child_of' param.

Fixes #30275.

git-svn-id: https://develop.svn.wordpress.org/trunk@30265 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2014-11-06 21:46:18 +00:00
parent 11843fe460
commit 642e826cd9
2 changed files with 22 additions and 1 deletions

View File

@ -1649,7 +1649,6 @@ function get_terms( $taxonomies, $args = '' ) {
// 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;
}

View File

@ -173,6 +173,28 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
$this->assertEmpty( $wpdb->last_error );
}
/**
* @ticket 30275
*/
public function test_exclude_with_hierarchical_true_for_non_hierarchical_taxonomy() {
register_taxonomy( 'wptests_tax', 'post' );
$terms = $this->factory->term->create_many( 2, array(
'taxonomy' => 'wptests_tax',
) );
$found = get_terms( 'wptests_tax', array(
'taxonomy' => 'wptests_tax',
'hide_empty' => false,
'exclude_tree' => array( $terms[0] ),
'hierarchical' => true,
) );
$this->assertEquals( array( $terms[1] ), wp_list_pluck( $found, 'term_id' ) );
_unregister_taxonomy( 'wptests_tax' );
}
/**
* @ticket 25710
*/