There seem to be many posts on showing start and end times but I can’t seem to get this code functioning. I’ve tried several different methods with no luck (some are still commented out below). It doesn’t seem like it should be a difficult task either. Can you have a look and make any recommendations?
FYI, for now this is a just a function and shortcode call just to see if I could get the data. If I can get it working, i’ll likely separate it into an plugin.
I’m sorry it’s really not easy to read your code within a forum reply. Can you post the entire contents of the code you’re working with into a pastebin or gist, then post a link here?
There’s a lot of code in that gist that isn’t needed and/or doesn’t really make sense, before you even get to outputting the date/times you’re throwing multiple undefined notices (which is also why you can’t get an event date to output).
That’s from line 28 and just above it – $datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $event->ID, $show_expired, false, $datetime_limit );
show_all_datetimes allows you to pull multiple datetimes from an event if you pas it to the shortcode, you aren’t currently initializing it so if you don’t pass it to the shortcode you get a notice.
EE_Event::$ID is from $event->ID as it should be a method, not a property, so it would be $event->ID() (the original code used $post->ID because the WP Post object in use in that code has the property, the EE EVent object your using, does not).
show_expired is basically the same problem as show_all_datetimes.
For line 28, if you want all of the datetimes from an event use:
Change any instance of $event->ID to $event->ID().
$event->post_title should be $event->name()
Right now for the first start date your using $datetime->get_raw( 'DTT_EVT_start' ) which is the unix timestamp from the DB
You can use $datetime->start_date() or $datetime->end_date() for those values in a readable format.
(If you use Kint Debugger and wrap an object (in this example $datetime) in d(); you’ll get a really nice easy to follow output that shows all of the available properties/method on that object).
Fixing the undefined notices and initializing the variables you need will fix most of the problems you having, for example:
To answer your question on how to output the start and end date/times for an event, you pull the datetimes for the event and then use the method available on datetime object. How you do that depends on which of the datetimes in the event you want (include expired? include archived? next upcoming? ‘First’ datetime? as you can see theres a lot of ways in which users want to pull datetimes)
Thanks Tony, i’ll be having a look but have a better understanding. As you can see, I left all the “trial” code in there so you can see what i’ve attempted already – they weren’t all utilized at the same time.
Yeah, I could see the additional code, but it was the code being used to pull in the datetimes that caused the issue you were having, you had no datetimes (because the variables being passed (mainly the Event ID) were not set so the function didn’t know what event to pull from).
The above gist should help point you in the right direction but please do let me know if you need further help.
Viewing 7 reply threads
The support post ‘How to Show Start Time and End Time for Events’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.