I have a search form in the home page and search form in the sidebar. Is it possible to make the search form in the home page show results as per a specific template and make the sidebar search form show a different template?
i want to make the homepage search box to show results in different way. Its a custom post. so if user uses that form it should only have data from that custom post. But the default wordpress search box in the sidebar should get the results from entire website.
eg. listing search page results with map
Thanks
I have a search form in the home page and search form in the sidebar. Is it possible to make the search form in the home page show results as per a specific template and make the sidebar search form show a different template?
i want to make the homepage search box to show results in different way. Its a custom post. so if user uses that form it should only have data from that custom post. But the default wordpress search box in the sidebar should get the results from entire website.
eg. listing search page results with map
Thanks
You can restrict a search to a custom post type by modifying a basic WP search form like this:
<form id="cptsearch" action="<?php echo home_url(); ?>" method="get">
<input type="text" name="s" />
<input type="hidden" name="post_type" value="POSTTYPENAME" />
<input id="searchsubmit" type="submit" alt="Search" value="Search" />
</form>
To select a specialized template for the custom post type search, add this filter in your functions file:
function template_chooser($template) {
global $wp_query;
$post_type = get_query_var('post_type');
if( $wp_query->is_search && $post_type == 'POSTTYPENAME' ) {
return locate_template('page_POSTTYPENAME.php');
}
return $template;
}
add_filter('template_include', 'template_chooser');
And of course, you must create the specialized search results template: page_POSTTYPENAME.php