WP_User_Query::get_search_sql( string $string, array $cols, bool $wild = false )
Used internally to generate an SQL string for searching across multiple columns
Parameters
- $string
-
(string) (Required)
- $cols
-
(array) (Required)
- $wild
-
(bool) (Optional) Whether to allow wildcard searches. Default is false for Network Admin, true for single site. Single site allows leading and trailing wildcards, Network Admin only trailing.
Default value: false
Return
(string)
Source
File: wp-includes/class-wp-user-query.php
protected function get_search_sql( $string, $cols, $wild = false ) { global $wpdb; $searches = array(); $leading_wild = ( 'leading' === $wild || 'both' === $wild ) ? '%' : ''; $trailing_wild = ( 'trailing' === $wild || 'both' === $wild ) ? '%' : ''; $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; foreach ( $cols as $col ) { if ( 'ID' === $col ) { $searches[] = $wpdb->prepare( "$col = %s", $string ); } else { $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); } } return ' AND (' . implode( ' OR ', $searches ) . ')'; }
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_user_query/get_search_sql