diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 7d341edae4..c898cbf18a 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -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; } diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 6dcc076837..3656b1aa7a 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -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 */