WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to get the last term that was searched, but when not in the search.php page. For that, I know, I could use get_search_query() function, but if user clicks on a post for example, so he is now in the single item and that function will retrieve an empty string. I want to preserve that search phrase and get it on other page.

Any ideas?


share|improve this question
are you looking for 2 day storage or more? Or are you looking for just as long as the users is still logged in. If user logs out then wipe search history – xLRDxREVENGEx May 23 '11 at 4:20
up vote 4 down vote accepted

Best solution would be to store the search phrase on the client-side via local storage or, where not available, in a cookie.

share|improve this answer

If you don't want to go the client-side way you might use the WordPress Transients API or just regular PHP sessions as suggested here: http://old.nabble.com/The-WordPress-way-to-store-temporary-per-user-data-(sessions)--td29723244.html

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.