Support

Home Forums Event Espresso Premium Echo Event Date in custom query

Echo Event Date in custom query

Posted: February 13, 2015 at 8:19 am

Viewing 2 reply threads


Peyton Earey

February 13, 2015 at 8:19 am

How can I echo out the event start date in this simple query?

<?php 
    $events = get_posts(array(
		'post_type'=>'espresso_events',
		'suppress_filters'=>false,
		'posts_per_page' => 4
	));
	
		foreach($events as $event) {
			
			$event_obj = $event->EE_Event;
			$link = $event_obj->get_permalink();

    ?>
    <div class="event">
        <a href="<?php echo $link; ?>">
            <h3 class="event_title"><?php echo $event_obj->name() ?></h3>
            <div class="event-start-date"></div>
        </a>
        </div>
<?php } ?>


Josh

  • Support Staff

February 13, 2015 at 4:45 pm

Hi there,

I recommend making use of the EEH Event view helper. Here is how you can use it in your example:

<?php

// Load Event View Helper
EE_Registry::instance()->load_helper('Event_View');
    $events = get_posts(array(
		'post_type'=>'espresso_events',
		'suppress_filters'=>false,
		'posts_per_page' => 4
	));

	foreach($events as $event) {
		
		$event_obj = $event->EE_Event;
		$link = $event_obj->get_permalink();
		$datetime = EEH_Event_View::get_primary_date_obj( $event->ID );
		$the_date = $datetime instanceof EE_Datetime ? $datetime->start_date( 'F j, Y' ) :  '';

?>
<div class="event">
    <a href="<?php echo $link; ?>">
        <h3 class="event_title"><?php echo $event_obj->name() ?></h3>
        <div class="event-start-date"><?php echo $the_date ?></div>
    </a>
    </div>
<?php } ?>


Peyton Earey

February 16, 2015 at 3:03 pm

Thanks!

Viewing 2 reply threads

The support post ‘Echo Event Date in custom query’ 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