Home › Forums › Calendar Products › Community Events › displaying all recurrences on a single event
- This topic has 5 replies, 2 voices, and was last updated 10 years, 5 months ago by
Brian.
-
AuthorPosts
-
December 2, 2015 at 3:16 pm #1034181
Allan Hendriks
ParticipantI don’t expect anyone to solve this for me. I would, however, love some direction.
I would love to be able to list recurring events on each single-event page. I’ve utilized a custom function on a custom single-event template that is inside my theme’s directory, like so:
echo display_proper_recurring_dates_ecp( get_the_ID() );
the idea is that, if applicable, it will list all the recurring events in the series. I’m trying to find an elegant way to do this..
in my functions.php file is the following…. (obviously only utilized if the calendar plugin is active!)
function display_proper_recurring_dates_ecp( $id ) {
if (!tribe_is_recurring_event() ) return; // nothing to show!
if (is_null($id)) $id = get_the_ID(); // if there’s an ommission$return .= ‘<p>There are more ‘.get_the_title( $id ).’ courses scheduled. ‘;
$link = get_permalink( $id );$return .= ‘See All.</p>’;
global $post;
$myStartDate = sp_get_start_date ( $id, true, ‘D M j Y G:i:s’);
$this_event_unix = date(‘U’, strtotime( $myStartDate ) ) ;$start_dates = tribe_get_recurrence_start_dates ( $post );
foreach($start_dates as $start_date){$event_start_unix = date(‘U’, strtotime( $start_date ) ) ;
if ($event_start_unix == $this_event_unix) continue; // skip the present event recurrnce
// since its the one we’re looking at..
$event_year = date(‘Y’, strtotime( $start_date ) ) ; // get the present year, and event
$this_year = date(‘Y’) ; // year, use to determine displaying
$date_format = tribe_get_date_format( $event_year == $this_year ? false : true );$event_link = get_permalink();
$event_end_unix = $event_start_unix + (int)get_post_meta( $id, ‘_EventDuration’, true);
$return .= ‘<p>‘ .
date($date_format, $event_start_unix) .
‘ – ‘ . date($date_format, $event_end_unix ).
‘</p>’;}
return $return;
}Really struggling with this one, and would love a point in the right direction. As you can see, I am familiar with pulling the meta data from the postID, however, its difficult for me to decipher how to pull individual listings and arrive at a list of applicable links.
I would really appreciate any help you can give me – and I’m happy to share whatever I figure out with the development team… If its worthy of course, LOL
Thanks! Allan
-
This topic was modified 10 years, 5 months ago by
Allan Hendriks.
-
This topic was modified 10 years, 5 months ago by
Brian.
December 2, 2015 at 3:18 pm #1034183Allan Hendriks
Participanti can see that my code has been parsed a little bit.
let me know if I need to clarify that for you. with thanks ADecember 3, 2015 at 6:44 am #1034618Brian
MemberHi,
I can try to help out here, but I am limited in supporting customizations.
I believe all the recurring instances have the first event’s id in the parent id field.
Could you query by that parent id to get all the instances?
Does that work?
December 3, 2015 at 12:08 pm #1034968Allan Hendriks
ParticipantThank you so much for your help!
A query for the post_parent was the key.
Don’t expect it to make the next release, but here is what I put together in case anybody on the team wants to use it..in the single-event.php template..
—————————————————————–
if (function_exists(‘display_proper_recurring_dates_ecp’)) {
global $post;
echo display_proper_recurring_dates_ecp( $post );
}
—————————————————————–in my functions.php
—————————————————————–
function display_proper_recurring_dates_ecp( $post ) {
if (!tribe_is_recurring_event() ) return;
if (is_null($post)) return false;$date_args = array( ‘posts_per_page’=>-1 ,
‘post_type’ => ‘tribe_events’,);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() ) { // The Loop
$date_format = tribe_get_date_format( $event_year == $this_year ? false : true );
$return .= ‘<p>This course is also offered: ‘;while ( $date_query->have_posts() ) {
$date_query->the_post();
$event_start_unix = date(‘U’, strtotime( get_post_meta( get_the_ID(), ‘_EventStartDate’, true ) ) ) ;
$event_end_unix = $event_start_unix + get_post_meta( get_the_ID(), ‘_EventDuration’, true);
$return .= ‘‘ .
date($date_format, $event_start_unix) .
‘ – ‘ . date($date_format, $event_end_unix ).
‘‘;
}
$return .= ‘</p>’;
}
wp_reset_postdata();return $return . ‘
‘;
}
—————————————————————–December 3, 2015 at 1:06 pm #1035011Allan Hendriks
Participantthanks Brian!
December 3, 2015 at 4:13 pm #1035137Brian
MemberI am glad to see you were able to figure it out.
Thanks for sharing too!
I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.
Thanks!
-
This topic was modified 10 years, 5 months ago by
-
AuthorPosts
- The topic ‘displaying all recurrences on a single event’ is closed to new replies.
