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
February 13, 2015 at 4:45 pm
Add New Note to this Reply
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
Add New Note to this Reply
Thanks!