title: Using pre_get_posts to build custom query not working
body: <p>I have been having a time trying to get this to work and looking over everything it seems like it should.</p>
  
  <p>I have a page where I am adding a custom sort function which alters the <a href="http://codex.wordpress.org/Class_Reference/WP_Query" rel="nofollow">WP Query</a> using <a href="http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts" rel="nofollow">pre_get_posts</a> and set_query_var</p>
  
  <p>In a nutshell I have a few select boxes where users select some things to filter the loop by.  Once a user submits the query for example my url will look like this: <a href="http://my-domain.com/gallery/?classroom=&amp;digital_items=&amp;kits_used=26155&amp;project_type=&amp;post_author=" rel="nofollow">http://my-domain.com/gallery/?classroom=&amp;digital_items=&amp;kits_used=26155&amp;project_type=&amp;post_author=</a></p>
  
  <p>So I added a post with the post meta of kits_used and added a few "kits", check my database for the postmeta and see the meta_value has the array like its supposed to: <code>a:2:{i:0;s:5:"26155";i:1;s:5:"26152";}</code></p>
  
  <p>However, I feel like something is wrong with my pre_get_posts function because when I choose the kit with the id of 26155, it says no posts are found.  Not sure if I am doing it correctly because its an array or if Im missing something else here.</p>
  
  <p>My function:</p>
  
  <pre><code>add_action('pre_get_posts', 'gallery_sort_query');
  
  function gallery_sort_query( $query )
  {
  // validate
      if( is_admin() )
      {
          return;
      }
  
      if( !$query-&gt;is_main_query() )
      {
          return;
      }
  
  // get original meta query
      $meta_query = $query-&gt;get('meta_query');
  
      // allow the url to alter the query
      if( !empty($_GET['kits_used']) )
      {
          $kits_used = explode(',', $_GET['kits_used']);
  
          //Add our meta query to the original meta queries
          $meta_query[] = array(
              'key'       =&gt; 'kits_used',
              'value'     =&gt; $kits_used,
              'compare'   =&gt; 'IN',
              );
      }
  
      if( !empty($_GET['project_type']) )
      {
          $project_type = explode(',', $_GET['project_type']);
  
          //Add our meta query to the original meta queries
          $meta_query[] = array(
              'key'       =&gt; 'project_type',
              'value'     =&gt; $project_type,
              'compare'   =&gt; 'IN',
              );
      }
  
      if( !empty($_GET['digital_items']) )
      {
          $digital_items = explode(',', $_GET['digital_items']);
  
          //Add our meta query to the original meta queries
          $meta_query[] = array(
              'key'       =&gt; 'digital_items',
              'value'     =&gt; $digital_items,
              'compare'   =&gt; 'IN',
              );
      }
  
      if( !empty($_GET['classroom']) )
      {
          $classroom = explode(',', $_GET['classroom']);
  
          //Add our meta query to the original meta queries
          $meta_query[] = array(
              'key'       =&gt; 'classroom',
              'value'     =&gt; $classroom,
              'compare'   =&gt; 'IN',
              );
      }
  
      if( !empty($_GET['post_author']) )
      {
          $author = $_GET['post_author'];
  
  
  
          $query-&gt;set( 'author' , $author );
  
      }
  
  // update the meta query args
      $query-&gt;set('meta_query', $meta_query);
  
  // always return
      return;
  
  }
  </code></pre>
  
  <p>Could really use some help here in case I am missing something, everything looks like it is lining up but for some reason it still isnt working except for the "Author" sort drop down.  Hopefully I have given too much info rather than not enough :)</p>