Home / Widgets / Event Data | Display Eventbrite Events
Duplicate Snippet

Embed Snippet on Your Site

Event Data | Display Eventbrite Events

Please note that this guide is intended for advanced users and developers. Our plugin already offers numerous options for filtering, selecting, and displaying events. However, it is important to distinguish the plugin's filtering capabilities from WordPress filters.
Refer: https://fullworksplugins.com/docs/display-eventbrite-events-in-wordpress/developer/filters-article/

This filter modifies the data returned by Display Eventbrite. It takes the start date and applies it to the end of multi-day events, making them appear as a single bookable entry in calendar layouts. After retrieving the data from the API or cache, you can apply filters to customize or add event data from other sources.

Filter example: ('wfea_api_results', $events, $atts)

In this slightly complex example, the end date of multi-day events is changed so that they appear as a single bookable day in calendar layouts.

(Note this code snippet applies for "Display Eventbrite Events Plugin" available here: https://fullworksplugins.com/products/widget-for-eventbrite/ )

Code Preview
php
<?php
add_filter(
	'wfea_api_results', //  hook to filter  returned event data before display
	/**
	 * @param $events
	 * @param $atts
	 *
	 * @return mixed
	 * @throws Exception
	 */
	function ( $events, $atts ) {
		if ( ! in_array(
			$atts['layout'],
			array(
				'cal_list',
				'cal'
			)
		) ) { // only impact cal_list and cal layout
			return $events;  
		}
		foreach ( $events as $key => $event ) {
			$start     = new \DateTime( $event->start->utc );
			$end       = new \DateTime( $event->end->utc );
			$start_day = $start->format( 'Y-m-d' );
			$end_day   = $end->format( 'Y-m-d' );
			if ( $start_day != $end_day ) {
				/**
				 * multiday event found
				 * need to grab end time from end date
				 * and rebuild both local and utc end date/time
				 */
				$start_local                = new \DateTime( $event->start->local );
				$start_day_local            = $start_local->format( 'Y-m-d' );
				$end_local                  = new \DateTime( $event->end->local );
				$end_time                   = $end->format( 'H:i:s' );
				$end_time_local             = $end_local->format( 'H:i:s' );
				$events[ $key ]->end->utc   = $start_day . 'T' . $end_time . 'Z';
				$events[ $key ]->end->local = $start_day_local . 'T' . $end_time_local;
			}
		}
		return $events;
	},
	10,      // priority
	2        // two arguments
);

Comments

Add a Comment