WP_Comment_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 ' AND (' . implode( ' OR ', $searches ) . ')';
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

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