Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 &ldquo;%s&rdquo; '), 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 );
                ?>
share|improve this question

1 Answer 1

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

 
discard

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.