Skip to content

Instantly share code, notes, and snippets.

@googlebe
Forked from aderaaij/acf-future-posts.php
Created December 23, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save googlebe/583acc815c401eacc4e6bd0701461779 to your computer and use it in GitHub Desktop.
Save googlebe/583acc815c401eacc4e6bd0701461779 to your computer and use it in GitHub Desktop.
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 cou…
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment