7

I was wondering if it is possible to have the wordpress search results displayed on a different page?

At the moment they are displayed on http://www.mysite.com/?s=searchterm but I would like them displayed on my search-results template page, so http://www.mysite.com/search/?s=searchterm.

Is this possible?

Any help greatly appreciated, S.

4 Answers 4

8

You created a page with the slug search to "capture" that URL, but WordPress by default already uses that URL for search results. So you were "lucky" that this worked for you, and this is the reason the redirect supermethod mentioned will work.

So, instead of creating a "fake" page to hold the template, you should just rename the template to search.php, like tnorthcutt suggested. If you still want to have content from the page defined in the admin area, I suggest you rename this page and get it via get_posts() or another method, because the main loop will contain search results, not this specific page.

3

I had a problem similar recently where the search results were going to the root rather than the /blog/ slug where I actually wanted the results displayed. I solved it by creating searchform.php and simply wrote a custom search template:

<form role="search" method="get" id="searchform" action="<?php echo home_url( '/blog/' ); ?>">
    <div>
        <label class="screen-reader-text" for="s">Search for:</label>
        <input type="text" value="" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="Search" />
    </div>
</form>

The secret is in the <?php echo home_url( '/blog/' ); ?> bit. By default wordpress will resolve to the home directory, like this <?php echo home_url( '/' ); ?>. So all you have to do is specify which directory you want your search results to display. If searchform.php exists in your theme it will use that. If not it will use the default form included in the wordpress core functions.

2

It looks like you may just need to rename your template page. Try creating a search.php template file: http://codex.wordpress.org/Theme_Development#Search_Results_.28search.php.29

1

Try this plugin (or read the source too see how the redirect is done - its only a few lines of code).

http://wordpress.org/extend/plugins/nice-search/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.