Make WordPress Core

Changeset 25164


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

Search term name and slug when the search arg is passed to get_terms(). Adds unit test.

Props wojtek.szkutnik.
Fixes #13992.

Location:
trunk
Files:
2 edited

Legend:

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

    r25162 r25164  
    13671367    }
    13681368
    1369     if ( !empty($search) ) {
    1370         $search = like_escape($search);
    1371         $where .= $wpdb->prepare( " AND (t.name LIKE %s)", '%' . $search . '%');
     1369    if ( ! empty( $search ) ) {
     1370        $search = like_escape( $search );
     1371        $where .= $wpdb->prepare( ' AND ((t.name LIKE %s) OR (t.slug LIKE %s))', '%' . $search . '%', '%' . $search . '%' );
    13721372    }
    13731373
  • trunk/tests/tests/term/getTerms.php

    r25162 r25164  
    140140        $this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
    141141    }
     142
     143    /**
     144     * @ticket 13992
     145     */
     146    function test_get_terms_search() {
     147        $term_id1 = $this->factory->tag->create( array( 'slug' => 'burrito' ) );
     148        $term_id2 = $this->factory->tag->create( array( 'name' => 'Wilbur' ) );
     149
     150        $terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'search' => 'bur', 'fields' => 'ids' ) );
     151        $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms );
     152    }
    142153}
Note: See TracChangeset for help on using the changeset viewer.