Search term name
and slug
when the search
arg is passed to get_terms()
. Adds unit test.
Props wojtek.szkutnik. Fixes #13992. git-svn-id: https://develop.svn.wordpress.org/trunk@25164 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9e96365b8e
commit
d34baebc1d
@ -1366,9 +1366,9 @@ function get_terms($taxonomies, $args = '') {
|
||||
$limits = '';
|
||||
}
|
||||
|
||||
if ( !empty($search) ) {
|
||||
$search = like_escape($search);
|
||||
$where .= $wpdb->prepare( " AND (t.name LIKE %s)", '%' . $search . '%');
|
||||
if ( ! empty( $search ) ) {
|
||||
$search = like_escape( $search );
|
||||
$where .= $wpdb->prepare( ' AND ((t.name LIKE %s) OR (t.slug LIKE %s))', '%' . $search . '%', '%' . $search . '%' );
|
||||
}
|
||||
|
||||
$selects = array();
|
||||
|
@ -139,4 +139,15 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
) );
|
||||
$this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 13992
|
||||
*/
|
||||
function test_get_terms_search() {
|
||||
$term_id1 = $this->factory->tag->create( array( 'slug' => 'burrito' ) );
|
||||
$term_id2 = $this->factory->tag->create( array( 'name' => 'Wilbur' ) );
|
||||
|
||||
$terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'search' => 'bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user