Lorenzo Orlando Caum
|
September 9, 2020 at 1:26 pm
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’ve also looked at the following posts as well as github for ideas with no luck
How to show START DATE/ END DATE and START TIME/ END TIME
Edit the Events Table View Template Add-on to show Start time and end time
Any help greatly appreciated as i’ve spent way too much time on this just trying to get the start and end times :)
Here is the code:
function ee_events_shortcode( $atts ) {
$events = EEM_Event::instance()->get_all(
array(
'order_by' => array( 'EVT_visible_on' => 'DESC' )
)
);
// content-header
echo "BEGIN:VCALENDAR" . " ";
echo "VERSION:2.0" . " ";
echo "PRODID:-//" . the_title() . "//NONSGML Events //EN" . " ";
echo "X-WR-CALNAME:" . the_title() . _e(' - Events','themeforce') . " ";
echo "X-ORIGINAL-URL:" . the_permalink() . " ";
echo "X-WR-CALDESC:" , the_title() . _e(' - Events','themeforce') . " ";
echo "CALSCALE:GREGORIAN" . " ";
foreach( $events as $event ) {
global $post;
//echo $event->name()." " . " ";
echo "BEGIN:VEVENT" . " ";
// get the next upcoming start date from all the available datetimes
//$external_url = $post->EE_Event->external_url();
//echo "Event URL:" . $external_url . " ";
$datetime_limit = $show_all_datetimes ? NULL : 1;
// Pull the datetimes for this event order by start_date/time
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $event->ID, $show_expired, false, $datetime_limit );
// Reset the datetimes pointer to the earliest datetime and use that one.
$datetime = reset( $datetimes );
if ($datetime instanceof EE_Datetime) {
echo 'ID:' . $event->ID . ' ';
echo 'Title:' . $event->post_title . ' ';
echo 'Start Date:' . $datetime->get_raw( 'DTT_EVT_start' ) . ' ';
echo 'End Date:' . $datetime->get_raw( 'DTT_EVT_end' ) . ' ';
// Loop over each datetime we have pulled from the database and output
foreach ($datetimes as $datetime) {
echo 'Datetime ID:' . $datetime->ID() . ' ';
echo 'Date:' . date_i18n( $date_format . ' ' . $time_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) ) . ' ';
echo 'Date:' . date_i18n( $date_format, strtotime( $datetime->start_date('Y-m-d') ) ) . ' ';
echo 'Start Date:' . date_i18n( $time_format, strtotime( $datetime->start_time('H:i:s') ) ) . ' ';
echo 'End Date:' . date_i18n( $time_format, strtotime( $datetime->end_time('H:i:s') ) ) . ' ';
//end foreach $datetimes
};
};
//$geteventdate = $event->first_datetime();
//$eventdate = date('Y-m-d H:i:s', strtotime($geteventdate->start_date()));
//echo "DTSTART:" . $eventdate . " ";
//echo "DTSTART:";
//do_shortcode( '[TIME_START]' );
//echo " ";
//do_shortcode( '[ESPRESSO_EVENTS_TABLE_TEMPLATE show_all_datetimes=TRUE]' );
//echo " ";
//echo "DTEND:" . "" . " ";
//echo "DTEND:" . $event->get('DTT_EVT_end'). " ";
echo "SUMMARY:" . $event->name() . " ";
echo "DESCRIPTION:" . $event->name() . " ";
//echo "DESCRIPTION:" . $event->description() . " ";
echo "END:VEVENT" . " ";
$startdate = "";
}
echo "END:VCALENDAR" . " ";
}
add_shortcode( 'ee_events_shortcode_output', 'ee_events_shortcode');
Here is the results page
Results
|