Tribe__Events__Repositories__Event::filter_by_multiday( bool $multiday = true )
Filters events to include only those that match the provided multi day state.
Contents
Please note that an event might be multi-day in its timezone but not in another; this filter will make the check on the event times localized to the event timezone. Furthermore the end of day cutoff is taken into account so, given a cutoff of 10PM an event starting at 10:30PM and ending at 11AM is not multi-day.
Parameters
- $multiday
-
(bool) (Optional) Whether to filter by events that are or not multi-day.
Default value: true
Source
File: src/Tribe/Repositories/Event.php
public function filter_by_multiday( $multiday = true ) { global $wpdb; $this->filter_query->join( "LEFT JOIN {$wpdb->postmeta} multiday_start_date ON ( {$wpdb->posts}.ID = multiday_start_date.post_id AND multiday_start_date.meta_key = '_EventStartDate' )" ); $this->filter_query->join( "LEFT JOIN {$wpdb->postmeta} multiday_end_date ON ( {$wpdb->posts}.ID = multiday_end_date.post_id AND multiday_end_date.meta_key = '_EventEndDate' )" ); // We're interested in the time only. $end_of_day_cutoff = tribe_end_of_day( 'today', 'H:i:s' ); if ( '23:59:59' === $end_of_day_cutoff ) { /* * An event is considered multi-day when the end date is not the same as the start date when * using the "natural" end-of-day cutoff. */ $compare = $multiday ? '!=' : '='; $this->filter_query->where( "DATE( multiday_end_date.meta_value ) {$compare} DATE( multiday_start_date.meta_value )" ); } else { /* * An event is considered multi-day when the end date is after the end-of-day cutoff of the start date. * Since the cut-off moves forward from midnight add 1 day to the start date. */ $compare = $multiday ? '>' : '<='; $this->filter_query->where( "multiday_end_date.meta_value {$compare} DATE_FORMAT( DATE_ADD( multiday_start_date.meta_value, INTERVAL 1 DAY ) , '%Y-%m-%d {$end_of_day_cutoff}' )" ); } }
Changelog
Version | Description |
---|---|
4.9 | Introduced. |