Support

Home Forums Event Espresso Premium Get dates for diffrent Datetimes in one event

Get dates for diffrent Datetimes in one event

Posted: December 13, 2016 at 9:44 am

Viewing 3 reply threads


yondbee

December 13, 2016 at 9:44 am

Hi, I use the ” new EE_Event_List_Query” to display list of event and order for start date. The problem is that i have some events with different datetimes and i dont know how to get the date, but the first datetime.

EE_Registry::instance()->load_helper('Event_View');
 $event_query = new EE_Event_List_Query(array(
   'posts_per_page'=> -1,
   'orderby' => 'start_date',
   'tax_query' => array(
	array(
	   'taxonomy' => 'espresso_event_categories',
	   'field'    => 'slug',
	   'terms'    => array('conciertos'),
	),
   ),
));
// after while()...
$x = $post->EE_Event->first_datetime(); 
$event_start = strtotime($x->start_date());

Here i just get the date of the first Datetime. Any help to get the others?


Tony

  • Support Staff

December 13, 2016 at 10:18 am

Hi there,

The EE_Events object has a datetimes_ordered() method that returns the datetimes within an event ordered by the order set within the event.

So something like:


$event = $post->EE_Event;

if ( $event instanceof EE_Event ) {
	$datetimes = $event->datetimes_ordered();

	foreach( $datetimes as $datetime ) {
		$datetime->e_start_date();
	}
}

Take a look at our model documentation here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

and Datetime docs here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/F–Datetime-System


yondbee

December 13, 2016 at 11:14 am

Hi Tony, thanks, that´s great really.
You think is posible make a conditional inside the loop to know if the event have more than 1 datetime?

$event = $post->EE_Event;

if ( $event instanceof EE_Event ) {
	$datetimes = $event->datetimes_ordered();

	foreach( $datetimes as $datetime ) {
	   if ($datetime>1){	
              $datetime->e_start_date();
           }
	}
}

Thanks a lot


Tony

  • Support Staff

December 13, 2016 at 3:48 pm

You’re code is checking if $datetime (which is the single element of the array) is greater than 1, I’m not sure what your trying to do?

You could use count() on $datetimes but really it depends on what your trying to do.

Viewing 3 reply threads

The support post ‘Get dates for diffrent Datetimes in one event’ 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.

Event Espresso