WP_Comment_Query::get_search_sql() WordPress Method

The WP_Comment_Query::get_search_sql() method is used to generate the SQL code that will be used to search for comments based on the specified search terms. This is useful for plugins that want to search through comments for specific data.

WP_Comment_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.


Top ↑

Return

(string) Search SQL.


Top ↑

Source

File: wp-includes/class-wp-comment-query.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.