Skip to content

Instantly share code, notes, and snippets.

@roxanneallard
Last active March 25, 2019 14:52
Show Gist options
  • Save roxanneallard/b6d4c3e0cabb7d730830439f5c8a201b to your computer and use it in GitHub Desktop.
Save roxanneallard/b6d4c3e0cabb7d730830439f5c8a201b to your computer and use it in GitHub Desktop.
Display categories using get_the_terms();
// Get terms for post
$terms = get_the_terms( $event->ID , 'tribe_events_cat' );
// init counter
$i = 1;
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
print $term->name;
// Add comma (except after the last theme)
echo ($i < count($terms))? ", " : "";
// Increment counter
$i++;
// Get rid of the other data stored in the object, since its not needed
unset($term);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment