Split get_search_sql(). See #15170. See #15032

git-svn-id: https://develop.svn.wordpress.org/trunk@16351 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
scribu 2010-11-13 18:18:45 +00:00
parent a4ee63c95a
commit e19c83933a
3 changed files with 46 additions and 26 deletions

View File

@ -70,32 +70,6 @@ class WP_Object_Query {
$qv['meta_query'] = $meta_query; $qv['meta_query'] = $meta_query;
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @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, $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$wild_char'";
}
return ' AND (' . implode(' OR ', $searches) . ')';
}
} }
?> ?>

View File

@ -341,6 +341,26 @@ class WP_Comment_Query extends WP_Object_Query {
return $comments; return $comments;
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @param string $string
* @param array $cols
* @return string
*/
function get_search_sql( $string, $cols ) {
$string = esc_sql( $string );
$searches = array();
foreach ( $cols as $col )
$searches[] = "$col LIKE '%$string%'";
return ' AND (' . implode(' OR ', $searches) . ')';
}
} }
/** /**

View File

@ -526,6 +526,32 @@ class WP_User_Query extends WP_Object_Query {
} }
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @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, $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$wild_char'";
}
return ' AND (' . implode(' OR ', $searches) . ')';
}
/** /**
* Return the list of users * Return the list of users
* *