Created
September 11, 2014 14:35
-
-
Save badcrocodile/91e002f96c0d038792dd to your computer and use it in GitHub Desktop.
Ordering Events by Advanced Custom Fields Date & Time Picker Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Credit to http://joshuaiz.com/words/ordering-events-by-advanced-custom-fields-date-time-picker-field/ | |
$time = current_time( 'timestamp' ); // Get current unix timestamp | |
// Set up custom query with meta_query to compare event start date with today's date | |
$args = array ( | |
'post_type' => 'event', // your event post type slug | |
'post_status' => 'publish', // only show published events | |
'orderby' => 'meta_value', // order by date | |
'meta_key' => 'event_start_date', // your ACF Date & Time Picker field | |
'meta_value' => $time, // Use the current time from above | |
'meta_compare' => '>=', // Compare today's datetime with our event datetime | |
'order' => 'ASC', // Show earlier events first | |
'posts_per_page' => 10, | |
); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) : | |
while ( $query->have_posts() ) : $query->the_post(); // Start loop | |
// Your custom loop code here | |
wp_reset_postdata(); | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment