Skip to content

Instantly share code, notes, and snippets.

@steve-brett
Created June 15, 2020 10:21
Show Gist options
  • Save steve-brett/c804fd4d204a9377ba386fdbfcd080be to your computer and use it in GitHub Desktop.
Save steve-brett/c804fd4d204a9377ba386fdbfcd080be to your computer and use it in GitHub Desktop.
Display all events in a given period
<?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