Displaying Custom Taxonomy Terms in WordPress Post

Explore our WordPress category, where you’ll find loads of helpful articles and tutorials for everyone, whether you’re just starting out or a pro developer. Learn about different WordPress themes and plugins that can be applied in various projects according to their specific requirements.
This piece of PHP code that retrieves the terms (categories) associated with a custom taxonomy called ‘location_cate’ for a specific post identified by its ID. Then, it iterates through each term and echoes the name of each term.
$terms = get_the_terms( $post->ID , ‘location_cate’ );
// Get the terms for the custom taxonomy ‘location_cate’ associated with the post ID.
foreach ( $terms as $term ) {
echo $term->name;
// Echo the name of each term.
} ?>
This code assumes that you have a custom taxonomy named ‘location_cate’ and that you’re using it to categorize posts. It retrieves the terms associated with the specific post and then iterates through each term to echo its name.