WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Template Tags/get search query

Description

The search query string is passed through esc_attr() to ensure that it is safe for placing in an html attribute. This function is used to get the query string when a user performs a search on the site. It returns the query string rather than display it; to display the query, you can use the_search_query().

Usage

<?php $search_query get_search_query(); ?>

Parameters

$escaped
(bool) (optional) Whether the result is escaped. Default true. Only use when you are later escaping it. Do not use unescaped.
Default: true

Return

(string) 
query.

Examples

Examples of the different usage methods.

<?php echo get_search_query(); ?>

<?php $search_query = get_search_query(); ?>

Changelog

since 2.3.0

Source Code

get_search_query() is located in wp-includes/general-template.php.

Related

See also index of Function Reference and index of Template Tags.