title: How to only apply a (Wordpress) meta query if it exists
body: <p>I am trying to apply filters in a list of products. Users will use select boxes on the front end and click a button to filter the products. </p>
  
  <p>Every product is it's own post, so I use WP_Query to get the posts. For example, I want all products with the color "red", the material "plastic" and the brand "Bikon". So I use;</p>
  
  <pre><code>$color = "red";
  $material = "plastic";
  $brand = "Bikon";
  $query = new WP_Query(array(
      'post_type'         =&gt; 'products',
      'posts_per_page'    =&gt;  6,
      'post_status'       =&gt; 'publish',
      'meta_query'    =&gt; array(
          'relation'      =&gt; 'AND',
          array(
              'key'       =&gt; 'color',
              'value'     =&gt; $color,
              'compare'   =&gt; '='
          ),
          array(
              'key'       =&gt; 'material',
              'value'     =&gt; $material,
              'compare'   =&gt; '='
          ),
          array(
              'key'       =&gt; 'brand',
              'value'     =&gt; $brand,
              'compare'   =&gt; '='
          )
      )
  ));
  </code></pre>
  
  <p>And this will work fine if every value get's set. But if only one of the select boxes is used, the other two values will be empty and the query will not return any posts. Is there any way to say "only use this array in the meta query if this value is set"?</p>