Last active
March 25, 2019 14:52
-
-
Save roxanneallard/b6d4c3e0cabb7d730830439f5c8a201b to your computer and use it in GitHub Desktop.
Display categories using get_the_terms();
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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