Grow your CSS skills. Land your dream job.

Display WordPress Search Query?

  • # October 31, 2012 at 12:10 am

    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?

    # March 25, 2013 at 9:35 pm

    i have the same issue! any help???

    # March 25, 2013 at 9:42 pm

    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](http://wordpress.org/support/topic/google-custom-search-query-string?replies=3 “the post on wordpress.org”); 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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".