Home › Forums › Calendar Products › Events Calendar PRO › How to display recurrence rules?
- This topic has 7 replies, 2 voices, and was last updated 10 years, 5 months ago by
George.
-
AuthorPosts
-
October 23, 2015 at 11:06 am #1017389
Brent Kozlowski
ParticipantHello,
How would I display (output) a custom recurrence rule? It appears there is a function for “tribe_event_is_all_day” & “tribe_event_is_multiday” in ../meta/details.php, but nothing for custom rules? If the conditions are not met it defaults to a single day event.
I also uncovered a bug… notice the start date. Is this why this event is not meeting the conditions for a multi-day?
“An event every 1 week(s) on Tuesday that begins at 1970-01-01 06:00 pm and lasts 0 day(s) and 0 hour(s), the last of which will begin on January 19, 2016”
Example of Desired Output
Start Date: November 3rd, 2015
End Date: January 19, 2016
Meets: Tuesdays @6pmOctober 23, 2015 at 11:20 am #1017395George
ParticipantHey @Tanya,
Can you clarify what you mean about “displaying a recurrence rule”, and what your goal with this is? You mention the functions tribe_event_is_multiday and tribe_event_is_all_day, but these functions have nothing to do with recurrence rules. And an event that is part of a custom recurrence pattern works fine with these functions…I’m not sure why you associated recurrence with these functions, but no such association exists. Let me know more details here and I will hopefully be able to help.
If all you mean here is, essentially, how to display something like “Meets: Tuesdays @6pm” from your example, then the best (and actually only) way to do this would be to add a custom function like I what I wrote for you here to your theme’s functions.php file:
function tanya_example_show_recurrence_description() {
$recurrence = get_post_meta( get_the_ID(), '_EventRecurrence', true );
return $recurrence['description'];
}Then determine where you want that information to appear, and use the principles of our Themer’s Guide to add it where you want on your site → https://theeventscalendar.com/knowledgebase/themers-guide/
We do not offer any help with customizations, so you will have to take the customization from there and do it on your own, but I hope that my writing code and stuff for you at least gets the ball rolling! 🙂
As for your issues with the start date, can you get started by sharing your System Information with us? Here’s how → https://theeventscalendar.com/knowledgebase/sharing-sys-info/
Thank you!
GeorgeOctober 23, 2015 at 11:45 am #1017407Brent Kozlowski
ParticipantThanks for the quick response! To clarify I was asking how to add an elseif statement for a recurring event in a meta/details.php. I’ve since added the following code with a call to “tribe_is_recurring_event()” to achieve it. Seems to work as intended.
What I’m confused on is how do I grab the “Final/last Date” from? Recurrence text or some other variable? I see the following variables, but none for the day of the week or last/final date.
Example:
$start_datetime = tribe_get_start_date();
$start_date = tribe_get_start_date( null, false );
$start_time = tribe_get_start_date( null, false, $time_format );
$start_ts = tribe_get_start_date( null, false, Tribe__Events__Date_Utils::DBDATEFORMAT );$last_date = ??????
$day_of_week = ??????$end_datetime = tribe_get_end_date();
$end_date = tribe_get_end_date( null, false );
$end_time = tribe_get_end_date( null, false, $time_format );
$end_ts = tribe_get_end_date( null, false, Tribe__Events__Date_Utils::DBDATEFORMAT );<?php //is recurring elseif ( tribe_is_recurring_event() ) : ?> <dt> <?php esc_html_e( 'Starts:', 'the-events-calendar' ) ?> </dt> <dd> <abbr class="tribe-events-abbr updated published dtstart" title="<?php esc_attr_e( $start_ts ) ?>"> <?php esc_html_e( $start_date ) ?> </abbr> </dd> <dt> <?php esc_html_e( 'Ends:', 'the-events-calendar' ) ?> </dt> <dd> <abbr class="tribe-events-abbr dtend" title="<?php esc_attr_e( $last_date ) ?>"> <?php esc_html_e( $last_date ) ?> </abbr> </dd> <dt> <?php esc_html_e( 'Meets:', 'the-events-calendar' ) ?> </dt> <dd> Every <?php esc_html_e($day_of_week) ?> <abbr class="tribe-events-abbr dtmeets" title="<?php esc_attr_e( $start_time ) ?>">@<?php esc_html_e( $start_time ) ?> </abbr> </dd>October 23, 2015 at 5:02 pm #1017505Brent Kozlowski
ParticipantAs far as I can tell I need to pull the “end” value from the meta_value which is in a serialized array?
meta_key = _EventRecurrence
meta_value = a:2:{s:5:”rules”;a:1:{i:0;a:7:{s:4:”type”;s:6:”Custom”;s:8:”end-type”;s:2:”On”;s:3:”end”;s:10:”2016-01-21″;s:9:”end-count”;s:0:””;s:6:”custom”;a:5:{s:4:”type”;s:6:”Weekly”;s:8:”interval”;s:1:”1″;s:4:”week”;a:1:{s:3:”day”;a:1:{i:0;s:1:”5″;}}s:10:”start-time”;a:3:{s:4:”hour”;s:2:”05″;s:6:”minute”;s:2:”00″;s:8:”meridian”;s:2:”pm”;}s:8:”duration”;a:3:{s:4:”days”;s:0:””;s:5:”hours”;s:1:”3″;s:7:”minutes”;s:0:””;}}s:14:”EventStartDate”;s:19:”2015-11-05 17:00:00″;s:12:”EventEndDate”;s:19:”2015-11-05 20:00:00″;}}s:10:”exclusions”;a:0:{}}
October 26, 2015 at 2:33 pm #1018693George
ParticipantHi @Tanya,
As noted we’re unfortunately not able to help that much with custom code-related questions, but the long and short of it here seems to be that you just need the “last date” an event in a series of recurring events will occur – is that correct?
If so, then you’re actually already quite close – when you have code like this, for example:
$end_ts = tribe_get_end_date( null, false, Tribe__Events__Date_Utils::DBDATEFORMAT );
That should work pretty well and you don’t have to stop here – you can take this new $end_ts variable and use it with PHP’s date() to generate other date data from it (e.g. the name of the Weekday, etc.)…
If that’s not meeting your needs but you think that pulling the end date from the serialized recurrence info will do the job, like you mention in your last reply here, then that’s fine too! It’s indeed a serialized array in storage – but if you use the WordPress function get_post_meta(), it will return an unserialized array ready for you to use like a normal associative array.
I hope this helps!
— George
October 27, 2015 at 3:23 pm #1019090Brent Kozlowski
ParticipantI really feel as though grabbing this value shouldn’t be considered custom programming and should be adequately documented if not readily retrievable for an “out-of-the-box” solution. I’ve spent more than a few hours researching this and this is the closest I have come with no luck whatsoever. Your help would be greatly appreciated as I’m sure there will be more than a few people this will help down the road.
Thanks!
$last_date = get_post_meta($post->ID,'my_key',true); foreach ($last_date as $myvalue) { echo $myvalue.', '; }October 27, 2015 at 6:16 pm #1019130Brent Kozlowski
ParticipantIf anyone is wondering what the correct solution for displaying the “end” date for a recurring event the solution can be found below:
$meta_data = get_post_meta(get_the_ID(), '_EventRecurrence', true); $end_ts = strtotime($meta_data['rules'][0]['end']); <?php esc_html_e( date('F j, Y', $end_ts)); ?>P.S. @george – I had to pay $40 for the solution to this and I’m sharing it with everyone here at no cost because that’s what a forum is meant for. I imagine quite a few people will benefit from it as this should be in the knowledge base or the codex and is completely unacceptable to have to hire someone for this. I hope you can use better judgement in the future.
October 29, 2015 at 7:55 am #1019767George
ParticipantHey @Tanya,
I’m sorry you’re disappointed with our support exchange. To be clear, I wrote this paragraph and it covers things pretty well in my opinion:
If that’s not meeting your needs but you think that pulling the end date from the serialized recurrence info will do the job, like you mention in your last reply here, then that’s fine too! It’s indeed a serialized array in storage – but if you use the WordPress function get_post_meta(), it will return an unserialized array ready for you to use like a normal associative array.
Now, I bolded the text above “in my opinion” because I thought that this information was plenty to get started with; for anyone who’s a bit familiar with WordPress, using get_post_meta() is a rather trivial thing to do.
I apologize for assuming certain things but am glad you eventually figured this out, and appreciate that you shared this information.
—
I know it doesn’t wholly resolve anything, but hopefully to add a bit more weight to my apology I wanted to share a coupon code I made just for you. You can use this when renewing a license, when buying a new license, anything at all. This reply I’m posting now is private, so this code is just for you and can only be used one time…but, at checkout, try this out:
tanya_is_awesomeThat should knock $40 off the total cart price. I hope that helps! 😀
Cheers,
George -
AuthorPosts
- The topic ‘How to display recurrence rules?’ is closed to new replies.
