How would it be possible, to create a log file and update it with the search queries of users, who are logged in?

I'd probably use fopen() and fwrite() php functions for saving the log files, but first I'd need a way to 'catch' the data I need. Checking if a user is logged in is easy, as well as getting the user name, but how would I get the search query variables every time a user uses the search function?

Thanks in advance, cheers!


You could use the get_search_query(); function. More in developer.wordpress

| improve this answer | |
  • Thanks, that will surely work if the search field is filled. What if the user runs a category/taxonomy search and leaves the search field empty? – galingong Nov 2 '17 at 12:00
  • What do you mean by the category/taxonomy search? – Drupalizeme Nov 2 '17 at 12:02
  • Most sites call it advanced search, or refined search, when the user is able to filter results based on category or other post data (e.g. price, color, size in a webshop). I'd also like to be able to log those search attributes. – galingong Nov 2 '17 at 12:34
  • 1
    @galingong then you should do it in the action function that this form sends the data for filtering. – Drupalizeme Nov 2 '17 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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