Last active
July 13, 2024 10:18
-
-
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.
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
<?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