Skip to content

Instantly share code, notes, and snippets.

@KinnaT
Last active January 12, 2017 21:14
Show Gist options
  • Save KinnaT/3c1ba2cf0ac72464cdad7d85566ae061 to your computer and use it in GitHub Desktop.
Save KinnaT/3c1ba2cf0ac72464cdad7d85566ae061 to your computer and use it in GitHub Desktop.
EE4 - grabbing various info from the db inside the WP loop for template use
<?php
if( have_posts() ){
while ( have_posts() ){ the_post(); // enter the WordPress loop
$id = get_the_ID(); // get the ID of the current post in the loop, post ID = EVT_ID
$terms = get_the_terms( $id, 'espresso_event_categories' ); // get the event categories for the current post
if ( $terms && ! is_wp_error( $terms ) ) {
$cats = array();
foreach ( $terms as $term ) {
// do something
}
}
$event = EEM_Event::instance()->get_one_by_ID( $id ); // get the event OBJECT using EE's existing method
$venue = $event->venue(); // get the venue object for the current event
$state = $venue instanceof EE_Venue ? $venue->state_abbrev(); // get the event venue's state, but you can use state_name() to get the full name
// using the event to get the first and last date for the entire event. Sub $datetime for $event to do it per datetime
$start_date = $event->start_date('j M Y');
$end_date = $event->end_date('j M Y');
$start_time = $event->start_time(get_option('time_format'));
$end_time = $event->end_time(get_option('time_format'));
?>
<!-- Do some awesome layout stuff here -->
<?php
}
}
espresso_pagination();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment