Support

Account

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>");