get_search_query() WordPress Function

The get_search_query() function is used to retrieve the search query string from the URL. This function is useful for themes and plugins that want to display the search query on the front-end.

get_search_query( bool $escaped = true ) #

Retrieves the contents of the search WordPress query variable.


Description

The search query string is passed through esc_attr() to ensure that it is safe for placing in an HTML attribute.


Top ↑

Parameters

$escaped

(bool)(Optional)Whether the result is escaped. Only use when you are later escaping it. Do not use unescaped.

Default value: true


Top ↑

Return

(string)


Top ↑

Source

File: wp-includes/general-template.php

function get_search_query( $escaped = true ) {
	/**
	 * Filters the contents of the search query variable.
	 *
	 * @since 2.3.0
	 *
	 * @param mixed $search Contents of the search query variable.
	 */
	$query = apply_filters( 'get_search_query', get_query_var( 's' ) );

	if ( $escaped ) {
		$query = esc_attr( $query );
	}
	return $query;
}


Top ↑

Changelog

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

Show More
Show More