Languages: English • 日本語 (Add your language)
Displays the search query for the current request, if a search was made.
This function can be used safely within HTML attributes (as in the "search box" example, below).
Use get_search_query to retrieve the value.
<?php the_search_query(); ?>
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 can display the search string on search result pages
<p>You searched for " <?php echo esc_html( get_search_query( false ) ); ?> ". Here are the results:</p>