WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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">

                            <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><!-- end search-wrap -->


and the search page

                global $wp_query, $query_string;

                $term_heading = '';
                $find_posts_in = '';

                $search = get_search_query();

                if ($search) :
                    $term_heading = sprintf( __('Searching  for Questions &ldquo;%s&rdquo; '), get_search_query());
                else :
                    $term_heading = __('Searching  ');

                if (is_array($find_posts_in)) :
                    $args = array_merge( $wp_query->query,
                            'post_type' => 'questions',
                            'post__in' => $find_posts_in
                else :
                     $args = array_merge( $wp_query->query,
                            'post_type' => 'questions'
                query_posts( $args );
share|improve this question

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_action( 'pre_get_posts', 'se39294_search_pre_get_posts' );

function se39294_search_pre_get_posts( $query ) {
    if ( $query->is_main_query() && is_search() ) {
        $query->set( 'post_type', array( 'page', 'post', 'questions' ) );
share|improve this answer
global $query_string;    
$query_args = explode("&", $query_string);
$search_args = array();

//including the default search queries 
foreach($query_args as $key => $string) {
    $query_split = explode("=", $string);
    $search_args[$query_split[0]] = urldecode($query_split[1]);
} // foreach

add your query filter arguments

 $search_args['post_type'] =  array( 'post', 'page', 'movie', 'book' ) ) );// all your post types to be included in the search

similarly include as many filters as you need eg for paging

$search_args['paged'] = (get_query_var('paged')) ? get_query_var('paged') : 1;


$result = new WP_Query( $search_args   );

$total_results     =             $result ->found_posts;

if ( $result ->have_posts() ) :    
... ... ...

Hope this helps!!!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.