Support » Fixing WordPress » Two search result on wordpress

  • The form goes like this..

    <form action="#" id="searchform" class="form-search" method="get" role="search">
                	<div class="search-options">
                    	<label class="radio">
                            <input type="radio" name="search-option" id="website" value="website" checked>
                            Website
                        </label>
                        <label class="radio">
                            <input type="radio" name="search-option" id="custom" value="custom">
                            Custom Post type
                        </label>
                    </div>
                 	<input type="text" id="s" name="s" value="" placeholder="Search" class="input-medium search-query">
                 	<input class="btn" type="submit" value="submit" id="searchsubmit">
     </form>

    How to Make two search-one whole website search and other custom post type search on same website?

Viewing 1 replies (of 1 total)
  • Thread Starter Sameer Humagain

    (@hsameerc)

    A simple function Works…..

    <?php
    /* ==============================================================
    //Search Filter
     ================================================================*/
    add_filter('pre_get_posts','SearchFilter');
    
    function SearchFilter($query) {
      if ($query->is_search) {
          if($_GET['post_type'] == "custom") {
            $query->set('post_type'), 'your_post_type_name');
          }
          elseif ($_GET['post_type']=="all"){ //Search All What you want to search add below if new custom post type is registered
              $query->set('your_post_type_name', array('your_custom-post1', 'your_custom-post2', 'your_custom-post3','your_custom-post4','custom-post5', 'post'));
          }
      }
      return $query;
    }
    
    add_filter('pre_get_posts','SearchFilter');
    ?>

    [ Signature moderated. ]

Viewing 1 replies (of 1 total)
  • The topic ‘Two search result on wordpress’ is closed to new replies.