Adding all recurring events to event meta details

Home Forums Calendar Products Events Calendar PRO Adding all recurring events to event meta details

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1540034
    Hannu
    Participant

    Hi,

    I have Events Calendar Pro with recurring events. On the single event meta details I would like to show all the recurring events, not only the single day as it is by default.

    I found some code snippets and I have added this to my themes /tribe-events/modules/meta/details.php:

    if(tribe_is_recurring_event( get_the_ID() ) ):
    		    $post = get_post( $event_id );
    		    $parent_id = $post->post_parent;
    
    		    if ( !$parent_id ) $parent_id = $event_id;
    
    				$recurrence_args = array(
    					'post_parent'    => $parent_id,
    					'meta_key'       => '_EventStartDate',
    					'orderby'        => 'meta_key',
    					'order'          => 'ASC',
    					'fields'         => 'ids',
    					'posts_per_page' => -1,
    				);
    
    				$child_events = tribe_get_events( $recurrence_args );
    
    		    if ( !empty ($child_events) ):
    					foreach( $child_events as $key => $value ) {
    							echo '<dd><abbr class="tribe-events-abbr tribe-events-start-date published dtstart">' . tribe_get_start_date( $value, false ) . '</abbr></dd>';
    					}
    				endif;

    But the problem is that e.g. if I have two events, this will show the date of the second event on both events meta. I would like that it lists both events.

    If I have two events:
    10.10.2018
    12.12.2018

    When viewing the 10.10.2018 event I would like to see in the meta details both event date:
    10.10.2018
    12.12.2018

    Thanks!

    #1540036
    Hannu
    Participant

    I tried to edit my post but I get “ERROR: Forum ID is missing.”

    So I wanted to be more clear:

    “When viewing either 10.10.2018 or 12.12.2018 event I would like to see in the meta details both event dates:
    10.10.2018
    12.12.2018”

    #1541355
    Jennifer
    Keymaster

    Hi Hannu,

    Thanks for reaching out!

    First, I do need to mention that customizations are outside the scope of support that we are able to provide in the forums, but I will try to point you in the right direction here.

    The original date in a recurring series is the parent, so if you want that date to be included as well, then you will need to echo out that start date before your foreach loop for the child events. Let me know if this gets you what you need and if you have any questions!

    Thanks,

    Jennifer

    #1545205
    Hannu
    Participant

    Hi, Thanks Jennifer. That worked and I’m now able to print the parent and the child event dates.

    BUT it only works when there is 2 events (one parent and one recurring event for it)

    When I add 3 events (one parent and 2 recurring events for it) then the last day is not shown for some reason.

    E.g. I have

    2018-09-27 (parent)
    2018-10-04
    2018-10-10

    I don’t see the 2018-10-10 event in the child event list. This query returns only one event which is the “2018-10-04”:

    				$recurrence_args = array(
    					'post_parent'    => $parent_id,
    					'meta_key'       => '_EventStartDate',
    					'orderby'        => 'meta_key',
    					'order'          => 'ASC',
    					'fields'         => 'ids',
    					'posts_per_page' => -1,
    				);
    
    				$child_events = tribe_get_events( $recurrence_args );

    Could you still help me what goes wrong with this? Thanks!

    #1545237
    Hannu
    Participant

    With some more searching I found this function tribe_get_recurrence_start_dates

    And it returns all three recurring events correctly.

    BUT it only has the start time of each event. And I would like to print each event with

    DATE + Start time + End time

    So I cannot fully use tribe_get_recurrence_start_dates.

    Why this tribe_get_events returns only one recurring event? Same seems to be reported here: https://theeventscalendar.com/support/forums/topic/getting-all-instances-for-recurring-events/

    #1545734
    Jennifer
    Keymaster

    Hi Hannu,

    I’m glad that you were able to get the parent displayed! Do you have the “Recurring event instances” option checked under Events > Settings > General? If so, you can try unchecking that and see if that gives you the rest of the instances for a series?

    #1546026
    Hannu
    Participant

    Hi, OK that fixed it! But I want to only show the first parent event of recurrent events. Is there a way to enable tribeHideRecurrence checkbox by default?

    (I could add ?tribe_paged=1&tribe_event_display=list&tribeHideRecurrence=1 into the navigation link, but is there any “cleaner” way to do it?)

    #1547286
    Hannu
    Participant

    I found the solution myself. In the setting I have “Recurring event instances” unchecked and I added this to my functions.php:

    function my_events_pre_get_posts( $query ) {
    
    	if(! is_singular( 'tribe_events' ) ) {
    		$query->query_vars['tribeHideRecurrence'] = 1;
    	}
    	return $query;
    }
    add_action( 'tribe_events_pre_get_posts', 'my_events_pre_get_posts', 1);

    On the events list pages I show event date range for recurring events with tribe_get_recurrence_start_dates

    #1547362
    Jennifer
    Keymaster

    Awesome! I’m glad that you got this working the way you need, and thanks for posting your solution here!

    If there is anything else that I can help with, please let me know.

    #1563740
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Adding all recurring events to event meta details’ is closed to new replies.