Created
June 15, 2020 10:21
-
-
Save steve-brett/c804fd4d204a9377ba386fdbfcd080be to your computer and use it in GitHub Desktop.
Display all events in a given period
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 | |
$start_of_week = date( 'Y-m-d', strtotime( 'monday this week' ) ); | |
$end_of_week = date( 'Y-m-d', strtotime( 'sunday this week' ) ); | |
$event_args['meta_query'] = array( | |
array( | |
'relation' => 'AND', | |
// Event starts before end of week, and finishes after start of week. | |
// This covers all instances of events overlapping the week period. | |
array( | |
'key' => 'event_start_date', | |
'compare' => '<=', | |
'value' => $end_of_week, | |
'type' => 'DATETIME' | |
), | |
array( | |
'key' => 'event_end_date', | |
'compare' => '>=', | |
'value' => $start_of_week, | |
'type' => 'DATETIME' | |
), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment