WP_Network_Query::get_search_sql() WordPress Method

The WP_Network_Query::get_search_sql() method is used to generate the SQL code for searching a WordPress network. This is a powerful method that can be used to search for networks by name, description, or other criteria.

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


Top ↑

Changelog

Changelog
VersionDescription
4.6.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.