I'm trying to create a search results page for our website and referring to the following documentation:


I created a new page template searchpage.php with the following comment block

 * Template Name: Search Page

Then I added a blank page in Wordpress, and assigned the above search template to the page from admin.

When using my search form, I am redirected to http://mysite.dev/search/?s=search_term as expected, however, I see 1 search result which appears to be of the search page itself.

When trying to access the search query, with get_search_query() I get nothing back even though it has been set in the URL.

I added the snippet as per the above documentation page to my template page:


global $query_string;

$query_args = explode("&", $query_string);
$search_query = array();

if( strlen($query_string) > 0 ) {
    foreach($query_args as $key => $string) {
        $query_split = explode("=", $string);
        $search_query[$query_split[0]] = urldecode($query_split[1]);
    } // foreach
} //if

$search = new WP_Query($search_query);

The only query parameter that is apparently set, is pagename=search, the s parameter is nowhere in sight?

I've updated to Wordpress 4.6, enabled the twentyfifteen theme, turned off all plugins, and seem to be getting the same behaviour on other themes as well?

Other observations I made is when I use change my search form to redirect to /, then I do get search results, but when I click on page 2 in pagination, it directs to a link like /page/2?s=search_term and I just see whatever my frontpage content is, no more search results?

Any idea what could be the issue?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.