Home › Forums › General Issues › Ordering/Filtering wp_query using ACF Date field › Reply To: Ordering/Filtering wp_query using ACF Date field
Giving it a little more thought, this should handle where the end date is not set, I think.
<?php
$recent_args = array(
'post_type' => 'event',
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'end_date',
'value' => $date_2,
'compare' => '<',
),
array(
'key' => 'end_date',
'compare' => 'NOT EXISTS',
),
),
array(
'relation' => 'OR',
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'DATE',
'value' => array($date_1, $date_2),
),
// if no end date has been set use start date
array(
'key' => 'date',
'compare' => 'BETWEEN',
'type' => 'DATE',
'value' => array($date_1, $date_2),
),
),
),
'orderby' => 'meta_value_num',
'order' => 'DESC',
'nopaging' => true
);
?>
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.