Last active
August 29, 2015 13:57
-
-
Save jdhobbsuk/9835444 to your computer and use it in GitHub Desktop.
WP_Query tweak for future events (eg. Events)
This file contains hidden or 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
| // the rest of your $args array | |
| $now = date('Ymd'); | |
| $date_key = 'date'; | |
| $args['meta_query'] = array( | |
| array( | |
| 'key' => $date_key, | |
| 'value' => $now, | |
| 'compare' => '>=', | |
| ), | |
| ); | |
| // Set query to order by custom field | |
| $args['meta_key'] = $date_key; | |
| $args['orderby'] = 'meta_value_num'; | |
| // the WP_Query call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This 'meta_query' addition will ensure that the only posts returned are ones where a custom value (date key) is a date in the future.
This is useful when you've got a post type like "Events" or "Meetings" but only want to show the items that are happening in the future.