Often you don’t want to query events between two set dates, but dates relative in time. For instance you might want to display upcoming events this month, or events just finished, etc.
Event Organiser allows you to give certain date-related query arguments in ‘relative date format’. For example, ‘tomorrow‘, ‘now‘, ‘+1 week‘, ‘third Thursday of this month‘ etc.
So what’s allowed?
The interpretation of relative strings is done via native php functions, so a full list of available formats can be found here. Please note which relative statements are available to you depends on the php version you are running WordPress on.
Friday 28th April 2017, 7:57pm (UTC)
27th April 2017, 12:00am (UTC)
//Events running in the coming week.. <?php $events = eo_get_events(array( 'event_end_after'=>'now', 'event_start_before'=>'+1 week', )); ?>
Please note that these strings are interpreted using PHP’s datetime object. See allowed statements here. Some PHP versions do not support all the statements.
For example ‘first day of this month‘ is only supported by PHP 5.3+
Events running from today until two months time
<?php $events = eo_get_events(array( 'event_end_after'=>'now', 'event_start_before'=>'+2 month' )); ?>
Events running this week (Monday to Sunday)
<?php eo_get_events(array( 'event_end_after'=>'last Monday', 'event_start_before'=>'this Sunday', 'showpastevents'=>1 )); ?>
Using the shortcode to list past events
[eo_events event_end_before="today" showpastevents=true ]
Using the shortcode to list events running this month
[eo_events event_start_before="last day of this month" event_end_after="first day of this month" showpastevents=true]
Using the shortcode to list events starting this month
[eo_events event_start_before="last day of this month" event_start_after="first day of this month" showpastevents=true]