Skip to content

Instantly share code, notes, and snippets.

@mikeoberdick
Last active July 13, 2024 10:18
Show Gist options
  • Save mikeoberdick/29c0cb6405db3058ec7e51cc0af4a624 to your computer and use it in GitHub Desktop.
Save mikeoberdick/29c0cb6405db3058ec7e51cc0af4a624 to your computer and use it in GitHub Desktop.
Show the custom taxonomy terms of a custom post type within the loop.
<?php
the_terms( get_the_ID(), 'event-type', '<ul class="event-types"><li>', '</li><li>', '</li></ul>' );
?>
<?php
//save them to a variable
<?php $terms = wp_get_post_terms(get_the_ID(), 'event-type');
//echo them out
if ( ! empty( $event_terms ) && ! is_wp_error( $event_terms ) ) :
echo '<ul class="event-types">';
foreach ( $event_terms as $term ) :
echo '<li>' . esc_html( $term->name ) . '</li>';
endforeach;
echo '</ul>';
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment