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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.