Template Tags/the search query
Материал из WordPress Wiki
Содержание |
Description
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).
Usage
%%% <?php the_search_query(); ?> %%%
Examples
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>
Show search query in results page
You can display the search string on search result pages
%%%You searched for " <?php the_search_query() ?> ". Here are the results:
%%%