Home › Forums › General Issues › get_posts, filtering by acf date field › Reply To: get_posts, filtering by acf date field
A date field is not stored as a date in the database. Remove the “type” argument from your meta query. Also alter the date format.
$startDate = date('Ymd', strtotime('-30 days'));
$posts = get_posts([
'post_type' => 'events',
'post_status' => 'publish',
'meta_query', array( array( 'key' => 'event_date', 'value' => $startDate, 'compare' => '>=')),
'numberposts' => 50,
]);
print("<pre>".print_r($posts,true)."</pre>");
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.