I have customised the standard Wordpress search.php and everything is working fine.
Now, my client would like to be able to add some content to the beginning of the search results page in the same way he can add content to any other page he has created in the admin area.
So, my thinking is to declare my custom search.php as a template with the name 'Search'. My client can then create a new page using the 'Search' template, add the content he needs and then display the search results.
How do I get the standard /?s=my+search+query to redirect to the new page AND deliver the information required to produce the results in my search.php?
I have tried this:
function fb_change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/custom-search-page/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
and this:
function add_rewrite_rules_search_query($aRules) {
$aNewRules = array('^search/(.+)?$' => 'index.php?pagename=custom-search-page&s=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules_search_query');
but no luck so far.
Thanks in advance for any help!