Created
November 24, 2021 16:46
-
-
Save schutzsmith/026df26511fab9364576ecf4d1e09afa to your computer and use it in GitHub Desktop.
WordPress query for a custom post type of "Events" that sorts by custom fields made in Advanced Custom Fields called "staart_date" and "start_time". I use two different fields because I wanted more control to do things like this.
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
<?php | |
return array( | |
'post_type' => 'events', | |
'posts_per_page' => '5', | |
'meta_key' => 'start_date', | |
'meta_query' => array( | |
'relation' => 'AND', | |
'date_clause' => array( | |
'key' => 'start_date', | |
'compare' => '=', | |
), | |
'time_clause' => array( | |
'key' => 'start_time', | |
'compare' => '=', | |
), | |
array( | |
'key' => 'start_date', // Check the start date field | |
'value' => date("Y-m-d"), // Set today's date (note the similar format) | |
'compare' => '>=', // Return the ones greater than today's date | |
'type' => 'DATE' // Let WordPress know we're working with date | |
), | |
), | |
'orderby' => array( | |
'date_clause' => 'ASC', | |
'time_clause' => 'ASC', | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do it with a single Date Time field: