Search uses index.php instead of search.php on renaming search field from “s”

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?

Related posts

Leave a Reply

2 comments

  1. 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).

  2. 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' );