title: Search posts based on multiple categories WordPress
body: <p>I am working on searching in wordpress i want to search text in multiple categories. here is my code </p>
  
  <pre><code>&lt;form method="post" action="&lt;?php bloginfo('home');?&gt;/?ptype=catsearch" &gt;
      &lt;input type="text" name="searchtext" size="40" /&gt;
          &lt;h2&gt;&lt;?php _e('Categories:'); ?&gt;&lt;/h2&gt;
          &lt;select name="category[]" multiple='multiple'&gt; 
              &lt;option value=""&gt;&lt;?php echo esc_attr(__('Please Select Your Choice')); ?&gt;&lt;/option&gt; 
                  &lt;?php $categories=  get_categories('show_count=0&amp;orderby=name&amp;echo=0&amp;hierarchical=true&amp;depth=1&amp;taxonomy=category&amp;exclude=1'); 
                  foreach ($categories as $category) {
                  $option = "&lt;option value=$category-&gt;term_id&gt;";
                  $option .= ucfirst($category-&gt;cat_name);
                  $option .= '&lt;/option&gt;';
                  echo $option;
              }
              ?&gt;
          &lt;/select&gt;
      &lt;input type="submit" id="searchsubmit" value="Search" name="submit"/&gt;   
  &lt;/form&gt; 
  </code></pre>
  
  <p>when this foms posts on catsearch.php file i takes all categoryids in array and create url see code below. if muliple categories selected it creates url like <code>http://abcd.com/?cat=3&amp;cat=7&amp;cat=8&amp;s=dasdasDS</code>. In this case it search the text only in last cat id. I think it overights the catids. I need if my search text found in any category then all posts should be displayed.</p>
  
  <pre><code>$categoryids = $_POST['category'];
  
              echo 'count is ---' .count($categoryids); 
  
              if($categoryids)
              {
                  foreach($categoryids as $categoryid)
                  {
                      $cat.=  'cat='.$categoryid.'&amp;';
                  }
                  echo $cat = trim($cat, '&amp;');
                  echo '&lt;br /&gt;';
                   $url .= '?'.$cat;
  
              }
  if($_POST['searchtext'])
              {
                  echo 'searchtext---'. $_POST['searchtext'];
                  echo '&lt;br /&gt;';
                  $url .= '&amp;s='.$_POST['searchtext'];
              } 
  &lt;META http-equiv="refresh" content="1;URL=&lt;?php echo get_bloginfo('url')."$url"; ?&gt;"&gt;
  </code></pre>