Show Your Search Query in WordPress
by Bandicoot Marketing on | Posted in Tutorials | 6 comments
Wouldn’t you like to be able to display the actual search term entered by your user on the search results’ page? Good thing there is a very simple way in WordPress to do that with the_search_query function. Just open up your search.php file and enter:
<?php the_search_query(); ?>
to display the search term that was entered. So something like this:
<?php echo 'Search Results for "'; the_search_query(); echo '"'; ?>
would display something that looked like this:
Search Results for “the search term”
Another cool little trick it to add the number of search results. Use this code:
<?php $mySearch =& new WP_Query("s=$s & showposts=-1"); $num = $mySearch->post_count; echo $num.' search results for "'; the_search_query(); ?>
to display something like:
18 search results for “the search term”
6 comments for “Show Your Search Query in WordPress”