I’ve taken what you’ve suggested on board here John – thanks for the input. I understand and can see how it should definitely work. However, the
OR relation is behaving like an
AND relation, and I can’t work out why.
Here’s what I have now:
$past_args = array( 'post_type' => 'event', '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 event/start date array( 'key' => 'start_date', 'compare' => 'BETWEEN', 'type' => 'NUMERIC', 'value' => array($date_1, $date_2), ) ), array( 'relation' => 'OR', // check event is not cancelled array( 'key' => 'status', 'value' => '"Cancelled"', 'compare' => 'NOT LIKE' ), // check event is not excluded from past events array( 'key' => 'status', 'value' => '"Exclude Past"', 'compare' => 'NOT LIKE' ) ) ), 'orderby' => 'meta_value_num', 'order' => 'DESC', 'nopaging' => false, 'posts_per_page' => '9999' );
OR in the date clause is working fine. In the second set of queries (against the ACF checkbox) though, I am seeing all events with either checkbox value, and only missing those with BOTH values checked. This is what i would expect of an
AND relation, no?
I removed the date clause entirely to try and isolate this but even then I can’t get the query to return events with only one of those two options checked.
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!
© 2022 Advanced Custom Fields.