Skip to main content
2 of 4
fixed unclosed if and added an example using wp_list_pluck.
RRikesh
  • 5.7k
  • 4
  • 31
  • 45

You can use get_the_terms(). I've adapted the following from an example on that page:

$terms = get_the_terms( $post->ID, 'visits' );
                        
if ( $terms && ! is_wp_error( $terms ) ) : 

    $visits_name = array();

    foreach ( $terms as $term ) {
        $visits_name[] = $term->name;
    }
endif;
                        
$terms_list = join( ", ", $visits_name );
echo $terms_list;

EDIT:

Using wp_list_pluck, as suggested by Telos, is much easier:

$terms = get_the_terms( $post->ID, 'visits' );
                        
if ( $terms && ! is_wp_error( $terms ) ) : 
  echo join( ',', wp_list_pluck( $terms, 'name' ) );
endif;
RRikesh
  • 5.7k
  • 4
  • 31
  • 45