Home Forums Event Espresso Premium Events archive not honouring earliest upcoming datetime

Events archive not honouring earliest upcoming datetime

Posted: August 20, 2015 at 5:38 am


August 20, 2015 at 5:38 am


So I’ve been working on getting the earliest upcoming datetime for an event do show as it’s date in the events archive listing.

There does not seem to be any functions that actually does this strangely enough..

Anyway. I solved it with this code:

global $post;
EE_Registry::instance()->load_helper( 'Event_View' );

$display_date = false;
$event_obj = $post->EE_Event;
// get the next upcoming start date from all the available datetimes
$datetimes = $event_obj->datetimes_ordered( $show_expired = false, $show_deleted = false );
foreach ( $datetimes as $datetime ) {
	$today = time();
	$temp_date = $datetime->start_date('Y-m-d');
	if( !$display_date ){
		$display_date = $temp_date;
	}elseif( $display_date && ( strtotime($display_date) > strtotime($temp_date) ) && ( $today < strtotime($temp_date) ) ){
		$display_date = $temp_date;


$datetime_object = new DateTime($display_date);
$month = date_i18n('M', strtotime($display_date));
<div class="post-date">
	<span class="date"><?php echo $datetime_object->format("d"); ?></span>
	<span class="month"><?php echo $month; ?></span>
	<span class="week">vecka <?php echo $datetime_object->format('W'); ?></span>
	<span class="year"><?php echo $datetime_object->format("Y"); ?></span>

However now I find that the query that fetches the events does not honor this order. The event which I’ve tested has its earliest upcoming datetime 26th august and latest upcoming datetime 29th september. That would mean the event should appear in august but instead it’s showing in september (but my date say august).

Any thoughts on this? Maybe a missed bug?


  • Support Staff

August 21, 2015 at 8:35 am

Can you try something like this instead?

$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, false, false, 1 );

$datetime = end( $datetimes );

$display_date = date_i18n( 'Y-m-d' . ' ' . 'H:i:s', strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );


August 21, 2015 at 10:35 am

Hi Josh,

Wouldn’t that just return the last datetime as well? What if I have one between the one that’s passed and the last datetime..

Also the issue about the archive query remains 🙂


  • Support Staff

August 21, 2015 at 12:50 pm

No it wouldn’t, because the last parameter passed to the get_datetimes_for_event_ordered_by_start_time() method sets the limit, and the limit is set to 1 in the example code I shared with you.

If you want to open up a pull request on github regarding the archive query the dev team can look into it.

The support post ‘Events archive not honouring earliest upcoming datetime’ 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.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: closed

Updated by  Josh 4 years, 9 months ago ago

Topic Tags


This topic is: not resolved
Do NOT follow this link or you will be banned from the site!