Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active September 23, 2015 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Pebblo/b9e0ced7289bd6331695 to your computer and use it in GitHub Desktop.
Save Pebblo/b9e0ced7289bd6331695 to your computer and use it in GitHub Desktop.
Output an events first cateory name and slug using the EE_Term object.
<?php
// The Event ID.
$event_id = 42;
//Pull the event object using the ID.
$event = EEM_Event::instance()->get_one_by_ID($event_id);
//Check we have an instance of an EE_Event
if ( $event instanceof EE_Event ) {
//Debug
//d($event);
//Pull the first EE_Term associated with the event.
$first_event_cat = $event->first_event_category();
//Check we have an instance of EE_Term
if ( $first_event_cat instanceof EE_Term ) {
//Debug
//d($first_event_cat);
/* Now we have an EE_Term object for that event */
/* We can output values using the object */
echo $first_event_cat->name();
echo "</br>";
echo $first_event_cat->slug();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment