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 want to customize the search. what i need is when user search for ex:

if user search for tools in search result will return result in following manners.

Pages page 1 page 2

Posts post 3 post 8

Products product 2 product 8

in above manners. while default search returns the mix result i want to filter the result.

first return all the post_type page, then after posts and at last products

how to filter search result in such manner.

what i did is i check the result with get_post_type() but pagination issue occur. pagination will not appear.

is there solution for it?

here is my code:

     if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>       <!-- Loop Start --!-->

    <div class="post post_row clearfix" id="<?php echo $post->post_name; ?>">

       <div class="wm_post_title clearfix">
         <a href="<?php echo get_permalink($post->ID); ?>" title="<?php the_title();?>"> <h2><?php the_title();?></h2></a>
          <ul class="post_tags">
                    <li class="published_dat"> <?php the_time(__('F j, Y', 'example')); ?></li>
                    <li class="categories"><?php the_category('<li>'); ?> </li>
   <div class="entry_content clearfix">
             <?php if(has_post_thumbnail()):?> <div class="featured_img"><?php the_post_thumbnail("thumbnail");?></div><?php endif; ?><!-- end featured_img -->
            <?php the_excerpt();?>
             <div class="learn_btn"><a href="<?php echo get_permalink($post->ID);?>">read more<i class="fa fa-arrow-circle-right"></i></a></div>

          </div><!-- end entry_content -->


          <?php endwhile; ?> <!-- Loop End --!-->
            <div class="pagenavi">
        <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>                <!-- Wp Pagenavi for Pagination --!-->
           </div><!-- end pagenavi -->
          <?php wp_reset_query();?>

            <?php else : ?>

            <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentytwelve' ); ?></p>
                <?php get_search_form(); ?>
              <?php endif;?>  <?php endif;?>

Need Help to have Such a output .

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.