Skip to content

Instantly share code, notes, and snippets.

@GeoffEW
Created February 8, 2018 19:35
Show Gist options
  • Save GeoffEW/984d0f1c269b22dc38d632975d0c46b2 to your computer and use it in GitHub Desktop.
Save GeoffEW/984d0f1c269b22dc38d632975d0c46b2 to your computer and use it in GitHub Desktop.
Adds the list of all recurrences to the single event view
<?php
/* Add this code within the single-event.php template */
if ( function_exists( 'cwd_display_recurring_events' ) ) {
global $post;
echo cwd_display_recurring_events( $post );
}
function cwd_display_recurring_events( $post ) {
$return = FALSE;
if ( ! tribe_is_recurring_event() ) {
return $return;
}
if ( is_null( $post ) ) {
return $return;
}
$date_args = array (
'posts_per_page' => - 1,
'post_type' => 'tribe_events',
'orderby' => 'meta_value',
'meta_key' => '_EventStartDate',
'order' => 'ASC'
);
if ( $post->post_parent != 0 ) {
$date_args['post_parent'] = $post->post_parent;
} else {
$date_args['post_parent'] = $post->ID;
}
$date_query = new WP_Query( $date_args );
if ( $date_query->have_posts() ) {
$date_format = tribe_get_date_format();
$return .= '
';
$return .= '
Other Course Dates
';
$return .= '
This course is also available on:
';
$return .= '
';
while ( $date_query->have_posts() ) {
$date_query->the_post();
$event_id = get_the_ID();
$event_start_unix = date( 'U', strtotime( get_post_meta( $event_id, '_EventStartDate', TRUE ) ) );
$event_start_time = tribe_get_start_date( $event_id, TRUE, 'ga' );
$event_end_time = tribe_get_end_date( $event_id, TRUE, 'ga' );
$return .= '
' .
date( $date_format, $event_start_unix ) .
' @ ' . $event_start_time . ' - ' . $event_end_time .
'
';
}
$return .= '
';
$return .= '
';
}
wp_reset_postdata();
return $return . ' ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment