Home › Forums › Calendar Products › Events Calendar PRO › Adding all recurring events to event meta details
- This topic has 8 replies, 2 voices, and was last updated 5 years, 10 months ago by Hannu.
-
AuthorPosts
-
May 28, 2018 at 5:21 am #1540034HannuParticipant
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.2018When viewing the 10.10.2018 event I would like to see in the meta details both event date:
10.10.2018
12.12.2018Thanks!
May 28, 2018 at 5:26 am #1540036HannuParticipantI 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”May 29, 2018 at 4:06 pm #1541355JenniferKeymasterHi 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
June 4, 2018 at 1:18 am #1545205HannuParticipantHi, 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-10I 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!
June 4, 2018 at 2:17 am #1545237HannuParticipantWith 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/
June 4, 2018 at 12:19 pm #1545734JenniferKeymasterHi 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?
June 4, 2018 at 8:39 pm #1546026HannuParticipantHi, 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?)
June 6, 2018 at 6:10 am #1547286HannuParticipantI 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
June 6, 2018 at 7:17 am #1547362JenniferKeymasterAwesome! 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.
June 28, 2018 at 9:35 am #1563740Support DroidKeymasterHey 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 -
AuthorPosts
- The topic ‘Adding all recurring events to event meta details’ is closed to new replies.