Events Calendar for FooEvents Shortcodes

Below, you’ll find a detailed guide on how to add the Events Calendar for FooEvents Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Events Calendar for FooEvents Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Events Calendar for FooEvents Plugin and the shortcodes it provides:

✩✩✩✩✩ () Active Installs: + Tested with: PHP Version:
Included Shortcodes:

Events Calendar for FooEvents [fooevents_calendar] Shortcode

The FooEvents Calendar shortcode is a powerful tool that displays a calendar on your website. It fetches and merges events from different sources, including FooEvents and bookings. The shortcode allows customization such as defining the time format, button text, and display type. It also supports multi-day events and non-product events. The layout can be adjusted to display weekends or not. The generated calendar can be styled by using a template from the theme directory or the plugin’s default template.

Shortcode: [fooevents_calendar]

Parameters

Here is a list of all possible fooevents_calendar shortcode parameters and attributes:

  • post – Specifies the product IDs to include in the calendar.
  • id – Changes the default identifier of the calendar.
  • include_cat – Defines the categories to include in the calendar.
  • cat – Sets the specific category to display in the calendar.
  • timeFormat – Sets the time format to either 24 hours or 12 hours.
  • buttonText – Specifies the text for the ‘Today’ button in the calendar.
  • defaultView – Determines the default view of the calendar (listWeek, listMonth).
  • displayEventEnd – Decides whether to display event end times or not.
  • weekends – Decides whether to display events on weekends or not.
  • type – Specifies the type of the calendar (e.g., list, grid).

Examples and Usage

Basic example – Displays a calendar with the default settings and no specific events.

[fooevents_calendar /]

Advanced examples

Display a calendar with specific events by referencing the product IDs. This example will only show events that are associated with the product IDs 1, 2, and 3.

[fooevents_calendar post="1,2,3" /]

Display a calendar with a unique ID and specific categories. This example will display a calendar with the ID ‘my_calendar’ and only show events from the categories ‘music’ and ‘sports’.

[fooevents_calendar id="my_calendar" include_cat="music,sports" /]

Display a calendar in ‘listWeek’ view. This example will display the calendar in a list view, showing all events for the current week.

[fooevents_calendar defaultView="listWeek" /]

Display a calendar excluding weekends. This example will display a calendar that doesn’t show events on weekends.

[fooevents_calendar weekends="false" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fooevents_calendar] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'fooevents_calendar', array( $this, 'display_calendar' ) );

Shortcode PHP function:

                    function display_calendar( $attributes ) {

		$include_cats = array();

		if ( empty( $attributes ) ) {

			$attributes = array();

		}

		$calendar_id = 'fooevents_calendar';
		$product_ids = '';

		if ( ! empty( $attributes['post'] ) ) {

			$product_ids = array_map( 'trim', explode( ',', $attributes['post'] ) );

		}

		if ( ! empty( $attributes['id'] ) ) {

			$calendar_id      = $attributes['id'] . '_fooevents_calendar';
			$attributes['id'] = $attributes['id'] . '_fooevents_calendar';

		} else {

			$attributes['id'] = $calendar_id;

		}

		if ( ! empty( $attributes['include_cat'] ) ) {

			$include_cats = array_map( 'trim', explode( ',', $attributes['include_cat'] ) );

		}

		if ( ! empty( $attributes['cat'] ) ) {

			$cat = $attributes['cat'];

		} else {

			$cat = '';

		}

		$attributes = $this->process_shortcodes( $attributes );

		$events_twenty_four_hour = get_option( 'globalFooEventsTwentyFourHour' );

		if ( 'yes' === $events_twenty_four_hour ) {

			$attributes['timeFormat'] = 'H:mm';

		}

		$attributes['buttonText'] = array( 'today' => __( 'Today', 'fooevents-calendar' ) );

		if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'is_plugin_active_for_network' ) ) {

			require_once ABSPATH . '/wp-admin/includes/plugin.php';

		}

		$display_type = '';
		if ( ! empty( $attributes['defaultView'] ) ) {

			$display_type = $attributes['defaultView'];

		} else {

			$display_type = 'calendar';

		}

		if ( 'listWeek' === $display_type || 'listMonth' === $display_type ) {

			$attributes['displayEventEnd'] = false;

		}

		if ( ! empty( $attributes['weekends'] ) && 'false' === $attributes['weekends'] ) {

			$attributes['weekends'] = false;

		}

		$events             = array();
		$non_product_events = array();

		if ( is_plugin_active( 'fooevents/fooevents.php' ) || is_plugin_active_for_network( 'fooevents/fooevents.php' ) ) {

			$events = $this->get_events( $include_cats, $product_ids );
			$events = $this->fetch_events( $events, $display_type, false );

		}

		$non_product_events = $this->get_non_product_events( $include_cats, $product_ids );
		$non_product_events = $this->fetch_events( $non_product_events, $display_type, false );

		$events = array_merge_recursive( $events, $non_product_events );

		if ( is_plugin_active( 'fooevents_multi_day/fooevents-multi-day.php' ) || is_plugin_active_for_network( 'fooevents_multi_day/fooevents-multi-day.php' ) ) {

			$fooevents_multiday_events = new Fooevents_Multiday_Events();
			$events                    = $fooevents_multiday_events->process_events_calendar( $events, $attributes );

		}

		if ( is_plugin_active( 'fooevents_bookings/fooevents-bookings.php' ) || is_plugin_active_for_network( 'fooevents_bookings/fooevents-bookings.php' ) ) {

			$fooevents_bookings = new FooEvents_Bookings( true );
			$booking_events     = $fooevents_bookings->get_bookings_for_calendar( $include_cats, $product_ids );

			$events = array_merge_recursive( $events, $booking_events );

		}

		$json_events = array_merge( $attributes, $events );
		$json_events = addslashes( json_encode( $json_events, JSON_HEX_QUOT | JSON_HEX_APOS ) );

		$local_args = array( 'json_events' => $json_events );

		if ( empty( $attributes['type'] ) ) {

			ob_start();

		}

		// Check theme directory for template first.
		if ( file_exists( $this->config->templatePathTheme . 'calendar.php' ) ) {

			include $this->config->templatePathTheme . 'calendar.php';

		} else {

			include $this->config->templatePath . 'calendar.php';

		}

		if ( empty( $attributes['type'] ) ) {

			$calendar = ob_get_clean();

			return $calendar;

		}

	}
                    

Code file location:

fooevents-calendar/fooevents-calendar/class-fooevents-calendar.php

Events Calendar for FooEvents [fooevents_events_list] Shortcode

The FooEvents Calendar shortcode is a dynamic tool that generates a list of events. It allows customization of event quantity, sorting order, and category inclusion. This shortcode fetches events from both FooEvents and FooEvents Bookings plugins, merges them, and sorts them by date. It also enables the overriding of the default ‘Book ticket’ term. The shortcode outputs a list of events, either from a theme template file or from a plugin template file, based on availability. Shortcode: [fooevents_events_list]

Shortcode: [fooevents_events_list]

Parameters

Here is a list of all possible fooevents_events_list shortcode parameters and attributes:

  • num – determines the number of events to display
  • sort – sets the sorting order of the events
  • post – specifies the ID of the events to be included
  • include_cat – includes events from specific categories
  • cat – filters events by a specific category
  • type – sets the output type for the event list

Examples and Usage

Basic example – In this example, we will use the ‘fooevents_events_list’ shortcode to display the list of the first 10 events, sorted in ascending order.

[fooevents_events_list num=10 sort=asc]

Advanced examples

Here, we are using the shortcode to display a list of events from specific posts and categories. The list will display the first 5 events in descending order from the posts with IDs 1,2,3 and from the categories with IDs 4,5,6.

[fooevents_events_list num=5 sort=desc post="1,2,3" include_cat="4,5,6"]

In the next example, we are using the shortcode to display a list of events from a specific category. The list will display the first 10 events in ascending order from the category with the slug ‘music’.

[fooevents_events_list num=10 sort=asc cat=music]

Lastly, in this example, we are using the shortcode to display a list of events from specific posts. The list will display the first 5 events in ascending order from the posts with IDs 1,2,3.

[fooevents_events_list num=5 sort=asc post="1,2,3"]

PHP Function Code

In case you have difficulties debugging what causing issues with [fooevents_events_list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'fooevents_events_list', array( $this, 'events_list' ) );

Shortcode PHP function:

                    function events_list( $attributes ) {

		$num_events   = '';
		$sort         = '';
		$cat          = '';
		$include_cats = array();

		if ( ! empty( $attributes['num'] ) ) {

			$num_events = $attributes['num'];

		} else {

			$num_events = 10;

		}

		if ( ! empty( $attributes['sort'] ) ) {

			$sort = strtolower( $attributes['sort'] );

		} else {

			$sort = 'asc';

		}

		$product_ids = '';

		if ( ! empty( $attributes['post'] ) ) {

			$product_ids = array_map( 'trim', explode( ',', $attributes['post'] ) );

		}

		if ( ! empty( $attributes['include_cat'] ) ) {

			$include_cats = array_map( 'trim', explode( ',', $attributes['include_cat'] ) );

		}

		if ( ! empty( $attributes['cat'] ) ) {

			$cat = $attributes['cat'];

		} else {

			$cat = '';

		}

		if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'is_plugin_active_for_network' ) ) {

			require_once ABSPATH . '/wp-admin/includes/plugin.php';

		}

		$events             = array();
		$non_product_events = array();

		if ( is_plugin_active( 'fooevents/fooevents.php' ) || is_plugin_active_for_network( 'fooevents/fooevents.php' ) ) {

			$events = $this->get_events( $include_cats, $product_ids );
			$events = $this->fetch_events( $events, 'events_list', true );

		}

		if ( is_plugin_active( 'fooevents_bookings/fooevents-bookings.php' ) || is_plugin_active_for_network( 'fooevents_bookings/fooevents-bookings.php' ) ) {

			$fooevents_bookings = new FooEvents_Bookings();
			$booking_events     = $fooevents_bookings->get_bookings_for_calendar( $include_cats );

			$events = array_merge_recursive( $events, $booking_events );

		}

		$non_product_events = $this->get_non_product_events( $include_cats );
		$non_product_events = $this->fetch_events( $non_product_events, 'events_list', true );

		$events = array_merge_recursive( $events, $non_product_events );

		$events = $this->sort_events_by_date( $events, $sort );

		if ( 'asc' === $sort && ! empty( $num_events ) && is_numeric( $num_events ) ) {

			$events = array_slice( $events, 0, $num_events, true );

		} elseif ( ! empty( $num_events ) && is_numeric( $num_events ) ) {

			$events = array_slice( $events, -$num_events, $num_events, true );

		}

		if ( empty( $attributes['type'] ) ) {

			ob_start();

		}

		foreach ( $events as $key => $event ) {

			if ( empty( $event ) ) {

				unset( $events[ $key ] );

			}

			$ticket_term = get_post_meta( $event['post_id'], 'WooCommerceEventsTicketOverride', true );

			if ( empty( $ticket_term ) ) {

				$ticket_term = get_option( 'globalWooCommerceEventsTicketOverride', true );

			}

			if ( empty( $ticket_term ) || 1 === (int) $ticket_term ) {

				$ticket_term = __( 'Book ticket', 'woocommerce-events' );

			}

			$events[ $key ]['ticketTerm'] = $ticket_term;

		}

		// Check theme directory for template first.
		if ( file_exists( $this->config->templatePathTheme . 'list-of-events.php' ) ) {

			include $this->config->templatePathTheme . 'list-of-events.php';

		} else {

			require $this->config->templatePath . 'list-of-events.php';

		}

		if ( empty( $attributes['type'] ) ) {

			$event_list = ob_get_clean();

			return $event_list;

		}

	}
                    

Code file location:

fooevents-calendar/fooevents-calendar/class-fooevents-calendar.php

Events Calendar for FooEvents [fooevents_event] Shortcode

The FooEvents Calendar plugin shortcode is designed to display specific event details on a page. This shortcode fetches event data using the product ID from the attributes. If the product ID exists, it retrieves the event post and ticket term. If no custom ticket term is set, it defaults to ‘Book ticket’. The event’s thumbnail URL is also fetched. Lastly, it checks for a template file in the theme directory, if not found, it uses the default template. The output is the event details.

Shortcode: [fooevents_event]

Parameters

Here is a list of all possible fooevents_event shortcode parameters and attributes:

  • product – Specifies the unique identifier of the event product

Examples and Usage

Basic example – Display an event by referencing its product ID.

[fooevents_event product=123 /]

In this basic example, the ‘fooevents_event’ shortcode is used to display an event. The ‘product’ attribute is used to specify the product ID of the event. Replace ‘123’ with the actual product ID of your event.

Advanced examples

Display multiple events by referencing their product IDs.

[fooevents_event product="123, 456, 789" /]

In this advanced example, the ‘fooevents_event’ shortcode is used to display multiple events. The ‘product’ attribute is used to specify the product IDs of the events. Replace ‘123’, ‘456’, and ‘789’ with the actual product IDs of your events.

Note: This advanced usage assumes that the ‘fooevents_event’ function and the shortcode have been modified to accept and process multiple product IDs.

PHP Function Code

In case you have difficulties debugging what causing issues with [fooevents_event] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'fooevents_event', array( $this, 'event' ) );

Shortcode PHP function:

                    function event( $attributes ) {

		$product_id = '';

		if ( ! empty( $attributes['product'] ) ) {

			$product_id = $attributes['product'];

		}

		ob_start();
		if ( ! empty( $product_id ) ) {

			$event = get_post( $product_id );

			$ticket_term = get_post_meta( $product_id, 'WooCommerceEventsTicketOverride', true );

			if ( empty( $ticket_term ) ) {

				$ticket_term = get_option( 'globalWooCommerceEventsTicketOverride', true );

			}

			if ( empty( $ticket_term ) || 1 === (int) $ticket_term ) {

				$ticket_term = __( 'Book ticket', 'woocommerce-events' );

			}

			if ( ! empty( $event ) ) {

				$thumbnail = get_the_post_thumbnail_url( $event->ID );

				// Check theme directory for template first.
				if ( file_exists( $this->config->templatePathTheme . 'event.php' ) ) {

					include $this->config->templatePathTheme . 'event.php';

				} else {

					require $this->config->templatePath . 'event.php';

				}
			}
		}

		$event_output = ob_get_clean();

		return $event_output;

	}
                    

Code file location:

fooevents-calendar/fooevents-calendar/class-fooevents-calendar.php

Conclusion

Now that you’ve learned how to embed the Events Calendar for FooEvents Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *