On this page
WP_Site_Query::get_search_sql( string $search, string[] $columns ): string
Used internally to generate an SQL string for searching across multiple columns.
Parameters
$searchstring Required-
Search string.
$columnsstring[] Required-
Array of columns to search.
Return
string Search SQL.
Source
File: wp-includes/class-wp-site-query.php. View all references
protected function get_search_sql( $search, $columns ) {
global $wpdb;
if ( false !== strpos( $search, '*' ) ) {
$like = '%' . implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $search ) ) ) . '%';
} else {
$like = '%' . $wpdb->esc_like( $search ) . '%';
}
$searches = array();
foreach ( $columns as $column ) {
$searches[] = $wpdb->prepare( "$column LIKE %s", $like );
}
return '(' . implode( ' OR ', $searches ) . ')';
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::esc_like() wp-includes/class-wpdb.php | First half of escaping for |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
Used By
| Used By | Description |
|---|---|
| WP_Site_Query::get_site_ids() wp-includes/class-wp-site-query.php | Used internally to get a list of site IDs matching the query vars. |
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_query/get_search_sql