treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Display Wordpress Search Query?

  • Hi- I have Google Custom Search set up on my website, and I want to display the search term at the top of the page. the_search_term(); doesn't work, as it's trying to query "s", but google custom search uses "q" as a term instead of "s".

    I was able to get the search box to point to my search results page by changing the form action from echo get_bloginfo('/'); (which is the default), to echo get_bloginfo('/search-results'); which is my results page. I also changed the parameter name="s" to name=q, which changes the query term in the URL from ?s= to ?q=.

    Now, as stated before, I'm trying to get the search term to display in the context of "Search Results: $term", but no matter what I try it doesn't seem to work.

    I did run across this snippet of code when doing some digging:

    <?php $g_search = apply_filters( 'get_search_query', get_query_var( 'q' )); ?>
    

    but that doesn't seem to change much, even after using echo $g_search, or echo get_search_query.

    Any suggestions on how to get this to work?

  • i have the same issue! any help???

  • Yes, yes, I actually was able to solve this myself!!! I had posted the same question over at the wordpress.org forums. You can get to my original post here; someone else besides you had this problem. It seemed like there weren't a lot of responses on this post, so I forgot about it...lol. Anyways, glad to have helped you out.