the_search_query()

Displays the contents of the search query variable.

Description

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

Source

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

Hooks

apply_filters( ‘the_search_query’, mixed $search )

Filters the contents of the search query variable for display.

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Show search query in search box
    If you have just performed a search, you can show the last query in the search box:

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

You must log in before being able to contribute a note or feedback.