title: wp_query not filtering tax_query correctly in pre_get_posts
body: <p>I'm having a problem with the following situation: I am creating a custom form for searching my custom post type (immobiliare) and attached to this I have 2 custom taxonomies: location and tipologia.</p>
  
  <p>My searchform.php is:</p>
  
  <pre><code>&lt;form role="search" method="get" id="searchform" action="&lt;?php echo home_url( '/' ); ?&gt;"&gt;
      &lt;input type="hidden" value="proceed" name="s" id="s" /&gt;
      &lt;fieldset&gt;
        &lt;legend&gt;Ricerca per:&lt;/legend&gt;
        &lt;label class="screen-reader-text" for="query"&gt;Testo:&lt;/label&gt;
            &lt;input type="text" value="&lt;?php the_search_query(); ?&gt;" name="query" id="query" /&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;label class="screen-reader-text" for="s"&gt;Tipologia:&lt;/label&gt;
            &lt;?php wp_dropdown_categories(array(
              'hide_empty' =&gt; 0,
              'taxonomy' =&gt; 'tipologia',
              'name' =&gt; 'tipologia',
              'show_option_all' =&gt; 'Nessuna Preferenza'
            )); ?&gt; 
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;label class="screen-reader-text" for="s"&gt;Località:&lt;/label&gt;
            &lt;?php wp_dropdown_categories(array(
              'hide_empty' =&gt; 0,
              'taxonomy' =&gt; 'location',
              'name' =&gt; 'location',
              'show_option_all' =&gt; 'Nessuna Preferenza'
            )); ?&gt; 
      &lt;/fieldset&gt;
      &lt;input type="submit" id="searchsubmit" value="Search" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>As you can see, I have 3 fields: 1 is a textfield and the other 2 are dropdowns with my taxonomies. I want the user to be able to search for these fields. I had to hack the "s" input type because it would not let me submit empty queries and added a "query" field instead.
  My functions.php file is as follows:</p>
  
  <pre><code>&lt;?php
  
    // Start LOGGING
    if(!function_exists('_log')){
      function _log( $message ) {
        if( WP_DEBUG === true ){
          if( is_array( $message ) || is_object( $message ) ){
            error_log( print_r( $message, true ) );
          } else {
            error_log( $message );
          }
        }
      }
    }
    // end LOGGING
  
    // start SEARCH FORM
    function ij_get_int($var){
      if (isset($var)) {
        $int_var = intval($var);
        if ($int_var &gt; 0)
          return $int_var;
      }
      return false;
    }
  
    function ij_get_str($var) {
      $str_var = esc_attr($var);
      if (strlen($str_var) &gt; 0)
        return $str_var;
      return false;
    }
  
    function custom_search_results($query) {
      if ($query-&gt;is_search &amp;&amp; $query-&gt;is_main_query()) {
        $tax_query = array(
          'relation' =&gt; 'AND',
        );
        $location = ij_get_int($_GET['location']);
        $tipologia = ij_get_int($_GET['tipologia']);
        if ($location) {
          array_push($tax_query, array(
             'taxonomy' =&gt;   'location',
             'field'    =&gt;   'id',
             'terms'    =&gt;   $location,
             'operator' =&gt;   'IN'
          ));
        }
        if ($tipologia) {
          array_push($tax_query, array(
             'taxonomy' =&gt;   'tipologia',
             'field'    =&gt;   'id',
             'terms'    =&gt;   $tipologia,
             'operator' =&gt;   'IN'
          ));
        }
        $query-&gt;set('tax_query', $tax_query);
  
        $query-&gt;set('s', ij_get_str($_GET['query']));
        $query-&gt;set('post_type', 'immobiliare');
      }
    }
  
    add_action('pre_get_posts', 'custom_search_results');
    // end SEARCH FORM
  
  ?&gt;
  </code></pre>
  
  <p>Here I hook into the response of my custom form and add:</p>
  
  <ul>
  <li>The actual query ("query" and not "s"), when the user inputs valid data.</li>
  <li>The filter by taxonomy, when needed.</li>
  </ul>
  
  <p>I have no clue why this is not working out (spent a day!), I can see my query coming back with the correct 's' parameter:</p>
  
  <pre><code>$query-&gt;set('s', ij_get_str($_GET['query']));
  </code></pre>
  
  <p>but not the taxonomy filter.</p>
  
  <p>What am I doing wrong? I want to use the standard Loop in my search.php file, so in some way I want my hook function to get automatically plugged into the loop. One curious thing is that if I create a new WP_Query object with the same setup (and not use the "set" method) it returns exactly what I want! I tried doing $query = new WP_Query... but this is not working too!!</p>
  
  <p>If I dump the query request on the top of my search.php I get the following:</p>
  
  <pre><code>SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND 0 = 1 AND (((wp_posts.post_title LIKE '%vil%') OR (wp_posts.post_content LIKE '%vil%')))  AND wp_posts.post_type = 'immobiliare' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
  </code></pre>
  
  <p>Does anyone have any hints to share? You would be really cool to give me a hand!
  Thanks
  Dan</p>