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.
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 viaget_posts()
or another method, because the main loop will contain search results, not this specific page.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 creatingsearchform.php
and simply wrote a custom search template: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. Ifsearchform.php
exists in your theme it will use that. If not it will use the default form included in the wordpress core functions.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.29Try 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/