Uses
| Uses | Description |
|---|---|
| wp-includes/wp-db.php: wpdb::esc_like() | First half of escaping for LIKE special characters % and _ before preparing for MySQL. |
| wp-includes/wp-db.php: wpdb::prepare() | Prepares a SQL query for safe execution. |
Used internally to generate an SQL string for searching across multiple columns.
(string) (Required) Search string.
(string[]) (Required) Array of columns to search.
(string) Search SQL.
File: wp-includes/class-wp-site-query.php
protected function get_search_sql( $string, $columns ) {
global $wpdb;
if ( false !== strpos( $string, '*' ) ) {
$like = '%' . implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';
} else {
$like = '%' . $wpdb->esc_like( $string ) . '%';
}
$searches = array();
foreach ( $columns as $column ) {
$searches[] = $wpdb->prepare( "$column LIKE %s", $like );
}
return '(' . implode( ' OR ', $searches ) . ')';
} | Version | Description |
|---|---|
| 4.6.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_query/get_search_sql