the_search_query()WP 2.1.0

Displays the contents of the search query variable.

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

1 time — 0.000017 sec (very fast) | 50000 times — 0.04 sec (speed of light) | PHP 7.1.2, WP 4.7.3
Hooks from the function


null. Ничего (null).





#1 Display the search query in the search input field

After the request has been sent it is convenient to leave this request in the field where it was entered (in the search box), you can do it this way:

<form method="get" id="searchform" action="<?php bloginfo( 'url' ) ?>/">
		<input type="text" value="<?php the_search_query() ?>" name="s" id="s" />
		<input type="submit" id="searchsubmit" value="Search" />

See also: get_search_form().


#2 Display the search query on the page:

<p>Search results by query: " <?php the_search_query() ?> ".</p>


Since 2.1.0 Introduced.

the_search_query() code WP 6.4.1

function the_search_query() {
	 * Filters the contents of the search query variable for display.
	 * @since 2.3.0
	 * @param mixed $search Contents of the search query variable.
	echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );