Support

Account

Home Forums General Issues get_posts, filtering by acf date field Reply To: get_posts, filtering by acf date field

  • Thanks. Years after I had time to go back to this project.
    WP_Query did the trick:

    	
            date_default_timezone_set("Europe/Zurich");
    	$dateNow = date('Y-m-d H:i:s');
    
            $args = array(
    		'post_type' => 'veranstaltungen',
    		'post_status' => 'publish',
    		'order' => 'DESC',
    		'orderby' => 'meta_value',
    		'meta_query' => array(
    			array(
    				'key'           => 'event_date',
    				'compare'       => '>=',
    				'value'         => $dateNow,
    				'type'          => 'DATETIME',
    			),
    		),
    		'numberposts' => -1,
    	);
    
    	$query = new WP_Query($args);
    
    	$posts = $query->posts;