WP_Comment_Query::get_search_sql()protectedWP 3.1.0

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

Method of the class: WP_Comment_Query{}

No Hooks.

Return

String. Search SQL.

Usage

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

Notes

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

Changelog

Since 3.1.0 Introduced.

WP_Comment_Query::get_search_sql() code WP 6.5.3

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