I am building a custom search form which has multiple search boxes and I rename them to "searchbox1" from "s". Now WP does not use search.php; instead the code is execured from index.php. How can I make it to use search.php?
2 Answers
Well, the s
is not just a name/ID, it's a query var, as the form's fields are injected by means of GET or POST to the URL which is then checked for the s
query var.
If the s
query var is defined, the search.php
(if present in your theme) will then be called automatically.
It's okay if you have multiple searchboxes having fields that share the same name. Each searchbox has its own form anyway.
In short: rename the search's input field back to s
(or tweak the redirects/rewrites etc. which is nonsense, in my opinion).
I think @tf’s suggestion is good. You should try to keep the name s
. If you cannot do that you can filter template_include
and return the template you want to use.
Idea, not tested:
if ( isset ( $_GET['searchbox1'] ) )
add_filter( 'template_include', 'get_search_template' );
-
@tf Thanks for your quick response. The issue here is that my search-form include two search-boxes. The search would search for values matching first search-box from one DB and those matching second search-box from another source. Hence, I need to have different names for the search-boxes, as I will need to parse the parameters passed to both. Commented Apr 21, 2013 at 10:14
-
Where should I write the code you mentioned. Just to mention in case this is helpful, I am trying to do this in form of a plugin. My plugin when activated will replace the default WP search-form and replace it with one which has two search-boxes. Since the search query also needs to be modified, so I have written some code to include my custom search-template. Commented Apr 21, 2013 at 10:19
-