WordPress at Your Fingertips
function is not described

WP_Site_Query::get_search_sql() protected WP 4.6.0

Used internally to generate an SQL string for searching across multiple columns.

{} It's a method of the class: WP_Site_Query{}

No Hooks.

Return

String. Search SQL.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_search_sql( $string, $columns );
$string(string) (required)
Search string.
$columns(string[]) (required)
Array of columns to search.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 4.6.0 Introduced.

Code of WP_Site_Query::get_search_sql() WP 5.8.2

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 ) . ')';
}