Skip to content

Instantly share code, notes, and snippets.

@zedejose
Last active February 4, 2018 15:12
Show Gist options
  • Save zedejose/dfd83253fa75c491f9b46c0acd94b027 to your computer and use it in GitHub Desktop.
Save zedejose/dfd83253fa75c491f9b46c0acd94b027 to your computer and use it in GitHub Desktop.
Code to exclude the single event we're viewing from the events list on the widget.
<?php
/*
* Code to exclude the single event we're viewing from
* the events list on the widget.
*
* Notes:
* - Only works with the Events Calendar plugin (Modern Tribe).
* - 'zewpgists_' is a prefix for all my gists. Replace with your own.
*
*/
add_filter( 'tribe_get_list_widget_events', 'zewpgists_exclude_single_from_widget' );
/**
* Exclude the current event from the widget list
*
* @param array $events Array of event posts.
* @return array Filtered array.
*/
function zewpgists_exclude_single_from_widget( $events ) {
if ( is_singular( 'tribe_events' ) && $events ) {
$unset = -1;
global $post;
$exclude = $post->ID;
foreach ( $events as $key => $event ) {
if ( $exclude === $event->ID ) {
$unset = $key;
break;
}
}
if ( $unset >= 0 ) {
unset( $events[ $unset ] );
}
}
return $events;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment