Make WordPress Core


Ignore:
Timestamp:
08/29/2013 04:23:30 PM (11 years ago)
Author:
wonderboymusic
Message:

Improve the include / exclude SQL generation in get_terms() by using IN and NOT IN where applicable. Adds unit tests for include / exclude.

Props sirzooro, duck_.

Fixes #11823.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/tests/term/getTerms.php

    r25161 r25162  
    120120        ), $terms_id_slug );
    121121    }
     122
     123    /**
     124     * @ti
     125     * cket 11823
     126     */
     127    function test_get_terms_include_exclude() {
     128        $term_id1 = $this->factory->tag->create();
     129        $term_id2 = $this->factory->tag->create();
     130        $inc_terms = get_terms( 'post_tag', array(
     131            'include' => array( $term_id1, $term_id2 ),
     132            'hide_empty' => false
     133        ) );
     134        $this->assertEquals( array( $term_id1, $term_id2 ), wp_list_pluck( $inc_terms, 'term_id' ) );
     135
     136        $exc_terms = get_terms( 'post_tag', array(
     137            'exclude' => array( $term_id1, $term_id2 ),
     138            'hide_empty' => false
     139        ) );
     140        $this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
     141    }
    122142}
Note: See TracChangeset for help on using the changeset viewer.