Home › Forums › General Issues › Query posts where end and/or start date are in the past › Reply To: Query posts where end and/or start date are in the past
I tried above solutions, unfortunately, none worked out for me. When I used ‘OR’ in the first wp_query argument, it hung up the page.
I ended up accidentally writing this code that solved the issue for me:
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'date_start',
'value' => date( 'Ymd' ),
'compare' => '=',
'type' => 'date'
),
array(
'relation' => 'AND',
array(
'key' => 'date_start',
'value' => date( 'Ymd' ),
'compare' => '<=',
'type' => 'date'
),
array(
'key' => 'date_end',
'value' => date( 'Ymd' ),
'compare' => '>=',
'type' => 'date'
),
),
)
Gist for description: https://gist.github.com/842c14baeb42d33ce90d1d1bf7a5de68
Not sure why the previous code didn’t work for me as the logic seems perfectly fine. I guess it’s just way to complex to be a query 🙂
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.