Get posts in the future with advanced custom fields date picker

Perhaps you have an events custom post type registered with WordPress. Perhaps you are using the date field for Advanced Custom Fields. I’d wager a guess you want to get all the events that have a date greater than (in the future) the current date. Who cares about past events?

 


$today = date('Ymd'); // Today's date
$args = array (
'post_type' => 'event', // Or your custom post type....
'meta_query' => array(
array(
'key' => 'event_date', //Advanced custom field key
'compare' => '>=',
'value' => $today,
)
),
);
$posts = new WP_Query($args);

Or paged:

$today = date('Ymd'); // Today's date

if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts( array(
'meta_query'=> array(
array(
'key' => 'event_date',
'compare' => '>',
'value' => $today,
'type' => 'DATE',
)),
'post_type' => 'events',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'posts_per_page' => 4,
'order' => 'ASC',
'paged' => $paged ) );

Posting code? Do it like this:

⟨pre⟩⟨code⟩ var foo = 'bar'; ⟨/code⟩⟨/pre⟩