From 6895dc9f8eab54b03781110988c5bfbcf0cf43f3 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 4 Sep 2013 19:41:08 +0000 Subject: [PATCH] Introduce `description__like` arg to `get_terms()`. Make `description__like` and `name__like` perform `LIKE`s with a wildcard on both sides of passed string. Previously, strings had to match the beginning of the name, so searching for `burrito` in `This is a burrito` would fail. Adds unit tests. Props aaroncampbell for the original patch, 5 years ago. Fixes #8214. Built from https://develop.svn.wordpress.org/trunk@25241 git-svn-id: http://core.svn.wordpress.org/trunk@25211 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 0d06c51a09..c5af198cc7 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1166,9 +1166,12 @@ function get_term_to_edit( $id, $taxonomy ) { * search - Returned terms' names will contain the value of 'search', * case-insensitive. Default is an empty string. * - * name__like - Returned terms' names will begin with the value of 'name__like', + * name__like - Returned terms' names will contain the value of 'name__like', * case-insensitive. Default is empty string. * + * description__like - Returned terms' descriptions will contain the value of + * 'description__like', case-insensitive. Default is empty string. + * * The argument 'pad_counts', if set to true will include the quantity of a term's * children in the quantity of each term's "count" object variable. * @@ -1222,7 +1225,7 @@ function get_terms($taxonomies, $args = '') { $defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', - 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', + 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $args = wp_parse_args( $args, $defaults ); $args['number'] = absint( $args['number'] ); @@ -1345,7 +1348,12 @@ function get_terms($taxonomies, $args = '') { if ( !empty($name__like) ) { $name__like = like_escape( $name__like ); - $where .= $wpdb->prepare( " AND t.name LIKE %s", $name__like . '%' ); + $where .= $wpdb->prepare( " AND t.name LIKE %s", '%' . $name__like . '%' ); + } + + if ( ! empty( $description__like ) ) { + $description__like = like_escape( $description__like ); + $where .= $wpdb->prepare( " AND tt.description LIKE %s", '%' . $description__like . '%' ); } if ( '' !== $parent ) {