Make WordPress Core

Changeset 30265


Ignore:
Timestamp:
11/06/2014 09:46:18 PM (10 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r30241 r30265  
    16501650    // Save queries by not crawling the tree in the case of multiple taxes or a flat tax.
    16511651    if ( ! $single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ) {
    1652         $args['child_of'] = false;
    16531652        $args['hierarchical'] = false;
    16541653        $args['pad_counts'] = false;
  • trunk/tests/phpunit/tests/term/getTerms.php

    r30113 r30265  
    172172        get_terms( 'post_tag', array( 'include' => array( 'unexpected-string' ), 'hide_empty' => false ) );
    173173        $this->assertEmpty( $wpdb->last_error );
     174    }
     175
     176    /**
     177     * @ticket 30275
     178     */
     179    public function test_exclude_with_hierarchical_true_for_non_hierarchical_taxonomy() {
     180        register_taxonomy( 'wptests_tax', 'post' );
     181
     182        $terms = $this->factory->term->create_many( 2, array(
     183            'taxonomy' => 'wptests_tax',
     184        ) );
     185
     186        $found = get_terms( 'wptests_tax', array(
     187            'taxonomy' => 'wptests_tax',
     188            'hide_empty' => false,
     189            'exclude_tree' => array( $terms[0] ),
     190            'hierarchical' => true,
     191        ) );
     192
     193        $this->assertEquals( array( $terms[1] ), wp_list_pluck( $found, 'term_id' ) );
     194
     195        _unregister_taxonomy( 'wptests_tax' );
    174196    }
    175197
Note: See TracChangeset for help on using the changeset viewer.