Last active
August 16, 2018 13:43
-
-
Save cliffordp/a77f4943e13f9e4e243564a210f82c83 to your computer and use it in GitHub Desktop.
Add links to ALL other occurrences in a recurring event series (not just future occurrences) -- looks like http://cl.ly/1h383J1b3L0P -- created for https://theeventscalendar.com/support/forums/topic/displaying-all-events-that-are-in-the-same-series-as-the-displayed-single-even/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// comments are above | |
// in the original /wp-content/plugins/the-events-calendar/src/views/single-event.php file | |
// | |
if ( ! defined( 'ABSPATH' ) ) { | |
die( '-1' ); | |
} | |
$events_label_singular = tribe_get_event_label_singular(); | |
$events_label_plural = tribe_get_event_label_plural(); | |
$event_id = get_the_ID(); | |
// START CUSTOM CODE from https://gist.github.com/cliffordp/a77f4943e13f9e4e243564a210f82c83 | |
// | |
// Add links to ALL other occurrences in a recurring event series (not just future occurrences) | |
// | |
if( ! function_exists( 'tribe_is_recurring_event' ) ) { | |
// bail because we need PRO active for recurring events | |
} else { | |
$recurrence_parent_id = wp_get_post_parent_id( $event_id ); | |
if ( empty( $recurrence_parent_id ) ) { | |
$recurrence_parent_id = $event_id; | |
} | |
if ( ! tribe_is_recurring_event( $event_id ) ) { | |
$recurrence_parent_id = 0; | |
} | |
if ( empty( $recurrence_parent_id ) ) { | |
// not a recurring event, bail | |
} else { | |
$recurrence_args = array( | |
'post_parent' => $recurrence_parent_id, | |
'meta_key' => '_EventStartDate', | |
'orderby' => 'meta_key', | |
'order' => 'ASC', | |
'fields' => 'ids', | |
'posts_per_page' => -1, | |
); | |
$all_event_ids_in_recurrence_series = tribe_get_events( $recurrence_args ); | |
if ( 1 < count( $all_event_ids_in_recurrence_series ) ) { | |
echo '<ul>'; | |
foreach( $all_event_ids_in_recurrence_series as $key => $value ) { | |
if ( $event_id !== $value ) { // do not include event we are currently viewing | |
printf( '<li><a href="%s">Other occurrence #%d</a></li>', esc_url( tribe_get_event_link( $value ) ), $key+1 ); | |
} | |
} | |
echo '</ul>'; | |
} else { | |
// nothing to do (should be that $event_id is the only one) | |
} | |
} | |
} | |
// END CUSTOM CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment