Load a specific page/template in its entirety with locate_template()

I am creating some advanced search functionalities, part of that means I removed the default search input with name="s" which WP_Query uses to set is_search to true and replaced it with a multiple select element with name="terms[]". I’m following Milo’s advice in the comment here (http://wordpress.stackexchange.com/questions/140793/removing-s-from-search-with-custom-parameters) but I have thus far been unsuccessful.

This is my most recent attempt:

function load_search_template($template) {
  global $wp_query;
  if(!is_admin() && $wp_query->is_main_query() && isset($_GET['terms'])) {
    $new_template = locate_template(array('base-search.php', 'base.php'));
    if ('' != $new_template) {
      return $new_template ;
    }
  }
  return $template;
}
add_filter('template_include', 'load_search_template', 999);

It loads the home page. If I try to do locate_template(array('search.php')) instead, it obviously loads search.php but without the theme wrapper.

So, how can I load the search page with the theme wrapper in this scenario?

Try changing 999 to 98.

If I leave the function as is and use 98 priority then I see my page header repeated infinitely.

If I change the priority and the function to $new_template = locate_template(array('search.php')); then I’m directed to the home page.

Any help on this at all?

It should work (passing search.php, not base-search.php) so if you’re getting redirected to the home page then it’s probably the logic in nice-search that’s causing the issue. It’s all towards the bottom of lib/cleanup.php but you can turn it off in lib/config.php.

With what I’ve been trying to accomplish I’ve had nice search disabled from the start :-/

And this?

Can’t remember if I commented that but how would it impact which template is loaded and whether it gets loaded with the theme wrapper?

You mentioned that you were redirected to the home page and that code is a fix for empty searches redirecting to the home page. I’m guessing that the two are related because invoking the wrapper how you are doing it should work.

Ok, when I finish coding this current branch I’ll switch back over and give this all a try. Thanks for following up!

Commenting out the roots_request_filter still results in being redirected to my project’s homepage, even when I locate search.php. If I change the priority of my template_include to 999 then I do end up on the search results page but without the wrapper (and the search query is lost).

Changing s to terms[] disables the roots_request_filter in the same way as commenting out the function would, as it’s looking for a form that’s no longer being sent.

If the search query is being lost then there’s an issue. Personally, I would switch back to one of the default themes and see if you can get the search working correctly before trouble shooting this.