WP_Network_Query::get_search_sql( string $search, string[] $columns ): string

In this article

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

Parameters

$searchstringrequired
Search string.
$columnsstring[]required
Array of columns to search.

Return

string Search SQL.

Source

protected function get_search_sql( $search, $columns ) {
	global $wpdb;

	$like = '%' . $wpdb->esc_like( $search ) . '%';

	$searches = array();
	foreach ( $columns as $column ) {
		$searches[] = $wpdb->prepare( "$column LIKE %s", $like );
	}

	return '(' . implode( ' OR ', $searches ) . ')';
}

Changelog

VersionDescription
4.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.