ACF – Order Custom Posts with datefield

To order custom post types with an ACF field named start_date and display posts with dates set in the future, this code proved effective for me.

The custom field start_date is part of the group field date_range and it’s stored as data_range_start_date in post meta by Advanced Custom Fields plugin.

array(
		'post_type'      => 'custom_post_type',
		'posts_per_page' => 15,
		'post_status'    => 'publish',
		'fields'         => 'ids',
		'meta_key'       => 'date_range_start_date',
		'orderby'        => array( 'meta_value' => 'ASC' ),
		'meta_query'     => array(
			'key'     => 'date_range_start_date',
			'value'   => date( 'Ymd' ),
			'type'    => 'DATE',
			'compare' => '>='
		),
	);

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.