i tried to figure this out but i can’t until know
i have new custom post type of questions
and i have other post types also like job listing
, resumes
etc
what i want here to make search for the post type questions only
here what i done
<?php global $app_abbr, $header_search; $header_search = true; ?>
<?php get_header(); ?>
<form action="<?php bloginfo('url'); ?>/" method="get" id="searchform">
<div class="search-wrap">
<div>
<input type="hidden" name="questions_search" value="true" />
<input type="hidden" name="post_type" value="questions" />
<input type="text" id="search" title="" name="s" class="text" placeholder="<?php _e('All Questions and answers'); ?>" value="<?php if (isset($_GET['s'])) echo get_search_query(); ?>" />
<label for="search"><button type="submit" title="<?php _e('Go'); ?>" class="submit"><?php _e('Go'); ?></button></label>
</div>
</div><!-- end search-wrap -->
</form>
and the search page
<?php
global $wp_query, $query_string;
$term_heading = '';
$find_posts_in = '';
$search = get_search_query();
if ($search) :
$term_heading = sprintf( __('Searching for Questions “%s” '), get_search_query());
else :
$term_heading = __('Searching ');
endif;
if (is_array($find_posts_in)) :
$args = array_merge( $wp_query->query,
array(
'post_type' => 'questions',
'post__in' => $find_posts_in
)
);
else :
$args = array_merge( $wp_query->query,
array(
'post_type' => 'questions'
)
);
endif;
query_posts( $args );
?>
A better approach is to address the main search query. @Dipesh’s answer is technically correct, but I would suggest using the
pre_get_posts
action instead to affect the intial query, rather than generating a new one. Much less work!add your query filter arguments
similarly include as many filters as you need eg for paging
Hope this helps!!!