A Wordpress URL that triggers a search includes a s
parameter and a value. So, something like https://example.com/?s=hello.
I want Wordpress to not render the search template, but to use whatever template should be shown if the s
parameter would not be present.
I can use the template_include
hook to force another template to be used, but this still loads the wrong posts.
I can also unset the querystring variable s
using the parse_query
hook. This then loads search results as if the search was for an empty string. If I also set is_search to false, I get a fatal error as a consequence of some include files (of my theme) being loaded multiple times.
What does work is capturing the s
in template_redirect
, and redirecting to the same URL but with the s
parameter replaced by another parameter (say mys
), and then handling that parameter instead on the resulting page. I find this a hack.
How do I make this work without replacing the query string variable?