How to use regular page template for search results?


I’m working on a Genesis child theme with a static front page. This front page contains a search box that just sets the ‘search’ query var. So it redirects to: http://baseurl/?search=foo

I’m handling the search query var in my page template, because I need to do some custom querying:

    $searchParam = get_query_var('search', null);

    $query_params = [
        'post_type' => 'any',
        'category_name' => 'stories',
        'orderby' => 'date',
        'posts_per_page' => 8,
        'paged' => 1,
        'post_status' => 'publish',
        'post__not_in' => get_option( 'sticky_posts' ),
        'ignore_sticky_posts' => 1,

    if ($searchParam) {
        $query_params['s'] = $searchParam;

    $result = new WP_Query( $query_params );
    ... etc ...

The problem

When this page is set as the front page and I’m doing a search, I’m getting a bare bones search result page and my custom page template isn’t being used. When I change the front page to another page it does work as intended. It seems to have something to do with the URL scheme, because if it’s the front page the search URL is something like: http://baseurl/?search=foo and when it’s not the front page it’s something like: http://baseurl/mypage/?search=foo

Any idea how I can set it up so it always uses the regular page template for the current page in case of a search?

, , Ruben 7 years 2017-03-16T13:55:17-05:00 0 Answers 79 views 0

Leave an answer