Home › Forums › ACF PRO › WP_Query based on ACF values (get values before loop) › Reply To: WP_Query based on ACF values (get values before loop)
Hi @juxprose
maybe you can use this query instead?
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => '-1',
'meta_query' => array(
'relation' => 'OR',
array(
'relation' => 'AND', // if no end date
array(
'key' => events_date_end,
'compare' => '=',
'value' => '',
),
array(
'key' => events_date_start,
'compare' => '>=',
'value' => $date,
),
),
array(
'relation' => 'AND', //if have end date
array(
'key' => events_date_end,
'compare' => '!=',
'value' => '',
),
array(
'key' => events_date_end,
'compare' => '>=',
'value' => $date,
),
),
),
'meta_key' => 'events_date_start',
'orderby' => 'meta_value',
'order' => 'ASC'
);
Keep in mind that I haven’t tested it yet. Please fix it if you find some errors.
I hope this helps.
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.