Home › Forums › Calendar Products › Events Calendar PRO › show start and end date of a recurring event
- This topic has 11 replies, 2 voices, and was last updated 9 years, 12 months ago by
Brook.
-
AuthorPosts
-
April 20, 2016 at 2:09 pm #1105074
davide notarantonio
ParticipantHi is there a way to show above a title of a recurring event the date of the first and of the last event of the serie, instead of the date of the day of the single (for example, from 13 april to 17 april 2016 instead of only 13…14…15…16 or 17 april)?
Thanks
-
This topic was modified 10 years ago by
davide notarantonio.
-
This topic was modified 10 years ago by
Brook.
April 20, 2016 at 11:54 pm #1105241Brook
ParticipantHowdy Davide,
That should be possible. I see on your site the dates show above the title, it’s likely your theme is overriding them. Do you have some experience programming or altering the code of WP themes? If so I could let you know the functions you’d need to call, and from there you will have to dig through your theme’s overrides to add those functions and adapt the example code to your theme. Would that work?
Cheers!
– Brook
April 21, 2016 at 12:01 am #1105245davide notarantonio
ParticipantHi, yes i created a theme that’s overriding the default one.
I do have experience, so yes, if you just tell me the function i have to call this would be enough to me.Thanks!
April 21, 2016 at 9:25 am #1105431Brook
ParticipantExcellent!
So what you will first need to do in your template is check if an event is recurring, and if so do the following. Otherwise procede as it normally does. The function to check for this is the aptly named tribe_is_recurring( $eventid ).
If each recurrence of your events starts and ends on the same day, then there is a super easy way to do this: tribe_get_recurrence_start_dates( $eventid ) . That will return an array of dates/times that each recurrence starts at. You can use the first and last one to get the dates of the entire range.
However, if the events end on a different day than they start, then the last date in the above array will not be correct since it’s the start date of that event, not the end. Thus it gets slightly more complicated. First you will need to get the post ID of each recurrence. I would run a query like this
SELECT ID FROM wp_posts WHERE post_parent='.$eventid.' OR ID='.$eventid.'That will give you each ID. On the first ID I would run tribe_get_start_date() . On the last I would run tribe_get_end_date() . And there you have it, the entire range of dates!
Does that all make sense? Will that work for you? Please let me know.
Cheers!
– Brook
April 28, 2016 at 1:59 am #1108102davide notarantonio
ParticipantHi, thanks for your answer.
I still have not tested it, as soon as i do the test, i let you know if it works or not
April 28, 2016 at 7:10 am #1108191Brook
ParticipantYou are welcome David! I appreciate you getting back. I’ll keep this topic open for as long as our tools allow so you have time to test and get back. Cheers!
– Brook
April 29, 2016 at 2:00 am #1108632davide notarantonio
ParticipantHi, i tried the ‘supereasy’ way, beacuse for me it’s enough to have start and end date, without the time.
http://www.notstudio.eu/atir/spettacolo/prova/2016-04-24/now my problem is: how can i use a different formato for start and end time?
I’d like to print something like this: ‘giovedì 14 aprile 2016’ while now it’s ‘2016-04-24 21:00:00’thanks for your help
April 29, 2016 at 9:15 am #1108812Brook
ParticipantHey I am happy the easy way worked!
Good questions. So the function your are using to display the events, tribe_get_start_date(), has a number of different arguments. Click on that link to familiarize yourself with it a bit. The first argument is the event ID, as you no doubt are already using. The next asks if you want to display the time. The third is the date format. It accepts a PHP Date Format string just like in every other area of WordPress. If you need some familiarizing with those checkout this guide.
Once you have setup the start date to use a given format, apply the same logic to the tribe_get_end_date() which accepts all of the same arguments including a date format string.
Is that what you were looking for?
Cheers!
– Brook
May 2, 2016 at 1:55 am #1109405davide notarantonio
ParticipantHi, Brook, thanks for your answer.
The function i’m using -as you sugegsted me- is tribe_get_recurrence_start_dates( $eventid ) and not tribe_get_start_date(), as the code i post you here below
$lavoro = tribe_get_recurrence_start_dates($eventid);
echo $lavoro[0];
$len = sizeof($lavoro);
echo ‘ / ‘. $lavoro[$len-1];I tried to use it as tribe_get_start_date(), but the function tribe_get_recurrence_start_dates( $eventid ) does not accept the date format parameter, beacuse its inferface has one single parameter $eventid.
So i have the same question as before; how can i manage the date format is givin me back the tribe_get_recurrence_start_dates( $eventid ) function?
May 2, 2016 at 7:59 am #1109528Brook
ParticipantOh I’m sorry, for a split second I was forgetting how tribe_get_recurrence_start_dates() works.
So what I would do is convert it to a proper PHP date using strtotime() . Then output it in any format using date() . Like this:
$format = 'Y-m-d D'; $lavoro = tribe_get_recurrence_start_dates( $eventid ); echo date( $format, strtotime( $lavoro[0] ) ); $len = sizeof($lavoro); echo ' / '. date( $format, strtotime( $lavoro[$len-1] ) );As mentioned in my previous post you might need to look into PHP date formats to find exactly the one you want. Would that work?
- Brook
May 3, 2016 at 3:09 am #1109917davide notarantonio
ParticipantHi Brook thanks fot your patience, i made some adjustements to make it print dates in italian and now it works 🙂
May 3, 2016 at 7:54 am #1110002Brook
ParticipantExcellent! I am happy you got this going. Thanks for reaching out!
Cheers!
– Brook
-
This topic was modified 10 years ago by
-
AuthorPosts
- The topic ‘show start and end date of a recurring event’ is closed to new replies.
