wordpress get the terms code example

Example 1: wordpress get taxonomy of a post

<?php $term_obj_list = get_the_terms( $post->ID, 'taxonomy_name' ); ?>

Example 2: wordpress get terms by taxonomy

You need to pass an additional argument to get_terms(). The default is to hide
"empty" terms-- terms which are assigned to no posts.

$terms = get_terms([
    'taxonomy' => $taxonomy,
    'hide_empty' => false,
]);

Example 3: woocommerce get post terms product

$term_obj_list = get_the_terms( $post->ID, 'taxonomy' );
$terms_string = join(', ', wp_list_pluck($term_obj_list, 'name'));