Make WordPress Core


Ignore:
Timestamp:
11/06/2014 09:46:18 PM (12 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.