WP_Site_Query::get_search_sql() WordPress Method
The WP_Site_Query::get_search_sql() method is used to generate the SQL code for searching a WordPress site. This is a powerful method that can be used to search for sites by name, description, or any other field.
WP_Site_Query::get_search_sql( string $search, string[] $columns ) #
Used internally to generate an SQL string for searching across multiple columns.
Parameters
- $search
(string)(Required)Search string.
- $columns
(string[])(Required)Array of columns to search.
Return
(string) Search SQL.
Source
File: wp-includes/class-wp-site-query.php
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 ) . ')'; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.6.0 | Introduced. |