Allow trailing wildcard user searches by appending *. see #15170

git-svn-id: https://develop.svn.wordpress.org/trunk@16170 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2010-11-03 19:31:11 +00:00
parent 0ab95195d0
commit 85e4a4a434
2 changed files with 10 additions and 3 deletions
+4 -2
View File
@@ -227,17 +227,19 @@ class WP_Object_Query {
*
* @param string $string
* @param array $cols
* @param bool $wild Whether to allow trailing wildcard searches. Default is false.
* @return string
*/
function get_search_sql( $string, $cols ) {
function get_search_sql( $string, $cols, $wild = false ) {
$string = esc_sql( $string );
$searches = array();
$wild_char = ( $wild ) ? '%' : '';
foreach ( $cols as $col ) {
if ( 'ID' == $col )
$searches[] = "$col = '$string'";
else
$searches[] = "$col LIKE '$string%'";
$searches[] = "$col LIKE '$string$wild_char'";
}
return ' AND (' . implode(' OR ', $searches) . ')';