Support

Account

Home Forums Backend Issues (wp-admin) WP Query – Multiple values in ACF Checkbox Reply To: WP Query – Multiple values in ACF Checkbox

  • Thanks John,

    I get it – and here’s what I’ve written:

    $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' => '4'
    );

    BUT – despite there clearly being an OR relation for the two queries on the status field, it is behaving like an AND relation. The event is only left out of the query if both boxes are checked.

    Any idea why this would be? Might it have something to do with being inside an AND relation? The OR relation on the date clause is working fine. I’ve pulled this right back to individual nested queries to try and isolate the problem but it has really stumped me.

    Thanks.