Advanced Custom Fields datepicker: Show only events with a date of today or in the future. Extra comments from Pasnon @ ACF Forums: f you needed to, you could also play with the comparison date, which is the first array in meta_query, currently set to
date("Y-m-d") which is today; if you were to make it
date("Y-m-d", strtotime("-1 day")) you could set it to show posts from YESTERDAY up til 30 days in the future. etc.
Hope this helps someone!
<?php
/*
* Display posts only from today and in the future:
* http://old.support.advancedcustomfields.com/discussion/6000/how-to-sort-posts-by-acf-date-and-display-only-future-posts
* by Pasnon
*/
$date_args = array(
'post_type' => 'events',
'meta_key' => 'event_start_date',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query'=> array(
array(
'key' => 'event_start_date',
'compare' => '>',
'value' => date("Y-m-d"),
'type' => 'DATE'
)
),
);
$date_query = new WP_Query( $date_args ); ?>
<?php
/*
* Display posts only from today or 30 days into the future: *
*/
$date_args = array(
'post_type' => 'events',
'meta_key' => 'event_start_date',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query'=> array(
array(
'key' => 'event_start_date',
'compare' => '>',
'value' => date("Y-m-d"),
'type' => 'DATE'
),
array(
'key' => 'event_start_date',
'compare' => '<=',
'value' => date("Y-m-d", strtotime("+30 days")),
'type' => 'DATE'
)
),
);
$date_query = new WP_Query( $date_args );