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.