Introduce description__like arg to get_terms(). Make description__like and name__like perform LIKEs 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
This commit is contained in:
Scott Taylor 2013-09-04 19:41:08 +00:00
parent ffe8f1b13a
commit 6895dc9f8e

View File

@ -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 ) {