From d34baebc1d8111c9c1014e11001957face778e52 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 29 Aug 2013 16:49:43 +0000 Subject: [PATCH] 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 --- src/wp-includes/taxonomy.php | 6 +++--- tests/tests/term/getTerms.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index f64aac0da9..4fdd4888a2 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -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(); diff --git a/tests/tests/term/getTerms.php b/tests/tests/term/getTerms.php index 82ce9a7dbf..2a946be693 100644 --- a/tests/tests/term/getTerms.php +++ b/tests/tests/term/getTerms.php @@ -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 ); + } }