Support

Account

Home Forums General Issues Content Filtering Using Fields – Issues Reply To: Content Filtering Using Fields – Issues

  • When multiple values are passed for multiple fields then you’ll need to use multiple nested meta queries.

    Looking at this query string ?size=small,large&color=black,white

    I’m going to assume that you want

    
    (size == small OR size == large) AND (color == black OR color == white)
    

    You’ll need to figure out out to put this into your loop, but the meta query you would need is something like this

    
    $meta_query = array(
      'relation' => 'AND',
       array(
         'relation' => 'OR',
          array(
            'key' => 'size',
            'value' => '"small"',
            'compare' => 'LIKE'
          ),
          array(
            'key' => 'size',
            'value' => '"large"',
            'compare' => 'LIKE'
          ),
       array(
         'relation' => 'OR',
          array(
            'key' => 'color',
            'value' => '"black"',
            'compare' => 'LIKE'
          ),
          array(
            'key' => 'color',
            'value' => '"white"',
            'compare' => 'LIKE'
          ),
       ),
    );
    

    A word of caution/warning, as the number filters grow and the number of selections made in each filter grows these like queries will take longer and longer to process until they finally time out and likely time out until it prevents the page from loading.