Home › Forums › Backend Issues (wp-admin) › WP Query – Multiple values in ACF Checkbox › Reply To: WP Query – Multiple values in ACF Checkbox
I’m not sure how do check LIKE
to exclude something – it would need to be LIKE
everything it isn’t, but since multiple values are in play here (it’s a checkbox rather than a radio button) I think I can’t say LIKE
a value and assume that means it is necessarily NOT LIKE
one of the others.
That said, I have done this:
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
// check to see if end date has been set
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($date_1, $date_2),
),
// if no end date has been set use start date
array(
'key' => 'start_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($date_1, $date_2),
)
),
array(
'key' => 'status',
'value' => '"Cancelled"',
'compare' => 'NOT LIKE'
),
array(
'key' => 'status',
'value' => '"Exclude Past"',
'compare' => 'NOT LIKE'
)
),
It seems to be working, although I don’t fully trust it. Now any event I designate as either Cancelled OR Exclude Past drops out of the past events list as I’d expect. Given that the clauses are part of an AND
relation I’m not sure I understand why that’s happening?
Also (and as an aside), I’m noticing that when wrapping OR
s inside AND
s like this things work pretty normally, but if I nest queries the other way around the page tends to hang instead of loading. Is that to be expected? Are there rules about which way round these things can be done?
Again, thanks so much John.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.