Skip to content

Instantly share code, notes, and snippets.

Created March 21, 2017 15:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0f5c54d6b3483b6a9bad46e80bc5783b to your computer and use it in GitHub Desktop.
Save anonymous/0f5c54d6b3483b6a9bad46e80bc5783b to your computer and use it in GitHub Desktop.
The Events Calendar Pro: Recurring events list in single event page.
<p>This event is planned on:</p>
<p class="current-date">
<?php
echo tribe_get_start_date();
echo ' - ';
echo tribe_get_end_date();
?>
</p>
<?php
global $post;
if( tribe_is_recurring_event($post) ) {?> <!-- check if event is recurring -->
<hr>
<p>The event is also available on:</p>
<ul class="calendar-list">
<?php
$parent = $post->post_parent;
if ( $parent ) : ?> <!-- if current page is child/recurring event page -->
<?php
/* get main/parent event */
$parent_title = get_the_title($parent); ?>
<a href="<?php echo get_permalink($parent); ?>">
<li>
<?php
echo $parent_title;
echo ': ';
echo tribe_get_start_date($parent);
?>
</li>
</a>
<?php
/* get all recurring events except current */
$args = array(
'post_parent' => $parent,
'post_type' => 'any',
'numberposts' => -1,
);
$children = get_children( $args );
foreach ($children as $child) {
if($post->ID != $child->ID){ ?>
<a href="<?php echo get_permalink($child); ?>">
<li>
<?php
echo get_the_title($child);
echo ': ';
echo tribe_get_start_date($child);
?>
</li>
</a>
<?php } ?> <!-- end if -->
<?php } ?> <!-- end foreach -->
<?php else : ?> <!-- if current page is parent/main event page -->
<?php
/* get all recurring events */
$args = array(
'post_parent' => $post->ID,
'post_type' => 'any',
'numberposts' => -1,
);
$children = get_children( $args );
foreach ($children as $child) { ?>
<a href="<?php echo get_permalink($child); ?>">
<li>
<?php
echo get_the_title($child);
echo ': ';
echo tribe_get_start_date($child);
?>
</li>
</a>
<?php }?> <!-- end foreach -->
<?php endif; ?>
</ul>
<?php } ?> <!-- end if is recurring event -->
@arelidev
Copy link

arelidev commented Aug 2, 2018

This works great, except I would recommend changing:
'post_type' => 'any'
to:
'post_type' => 'tribe_events'
otherwise you'll pull featured images or any other attached media.

@pictibe
Copy link

pictibe commented Oct 15, 2019

It seems not wo work anymore?
No recurring event would be displayed.

Do you have another solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment