Make WordPress Core

Ticket #8214: 8214.3.diff

File 8214.3.diff, 4.0 KB (added by wonderboymusic, 11 years ago)
  • tests/phpunit/tests/term/getTerms.php

     
    150150                $terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'search' => 'bur', 'fields' => 'ids' ) );
    151151                $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms );
    152152        }
     153
     154        function test_get_terms_like() {
     155                $term_id1 = $this->factory->tag->create( array( 'name' => 'burrito', 'description' => 'This is a burrito.' ) );
     156                $term_id2 = $this->factory->tag->create( array( 'name' => 'taco', 'description' => 'Burning man.' ) );
     157
     158                $terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'bur', 'fields' => 'ids' ) );
     159                $this->assertEqualSets( array( $term_id1 ), $terms );
     160
     161                $terms2 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'bur', 'fields' => 'ids' ) );
     162                $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms2 );
     163
     164                $terms3 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'Bur', 'fields' => 'ids' ) );
     165                $this->assertEqualSets( array( $term_id1 ), $terms3 );
     166
     167                $terms4 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'Bur', 'fields' => 'ids' ) );
     168                $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms4 );
     169
     170                $terms5 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'ENCHILADA', 'fields' => 'ids' ) );
     171                $this->assertEmpty( $terms5 );
     172
     173                $terms6 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'ENCHILADA', 'fields' => 'ids' ) );
     174                $this->assertEmpty( $terms6 );
     175
     176                $terms7 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'o', 'fields' => 'ids' ) );
     177                $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms7 );
     178
     179                $terms8 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => '.', 'fields' => 'ids' ) );
     180                $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms8 );
     181        }
    153182}
  • src/wp-includes/taxonomy.php

     
    11661166 * search - Returned terms' names will contain the value of 'search',
    11671167 * case-insensitive. Default is an empty string.
    11681168 *
    1169  * name__like - Returned terms' names will begin with the value of 'name__like',
     1169 * name__like - Returned terms' names will contain the value of 'name__like',
    11701170 * case-insensitive. Default is empty string.
    11711171 *
     1172 * description__like - Returned terms' descriptions will contain the value of
     1173 *  'description__like', case-insensitive. Default is empty string.
     1174 *
    11721175 * The argument 'pad_counts', if set to true will include the quantity of a term's
    11731176 * children in the quantity of each term's "count" object variable.
    11741177 *
     
    12221225        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    12231226                'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(),
    12241227                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
    1225                 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '',
     1228                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '',
    12261229                'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' );
    12271230        $args = wp_parse_args( $args, $defaults );
    12281231        $args['number'] = absint( $args['number'] );
     
    13451348
    13461349        if ( !empty($name__like) ) {
    13471350                $name__like = like_escape( $name__like );
    1348                 $where .= $wpdb->prepare( " AND t.name LIKE %s", $name__like . '%' );
     1351                $where .= $wpdb->prepare( " AND t.name LIKE %s", '%' . $name__like . '%' );
    13491352        }
    13501353
     1354        if ( ! empty( $description__like ) ) {
     1355                $description__like = like_escape( $description__like );
     1356                $where .= $wpdb->prepare( " AND tt.description LIKE %s", '%' . $description__like . '%' );
     1357        }
     1358
    13511359        if ( '' !== $parent ) {
    13521360                $parent = (int) $parent;
    13531361                $where .= " AND tt.parent = '$parent'";