Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

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;
    }
    $terms_list = join( ", ", $visits_name );
    echo $terms_list;
endif;
                        

EDIT:

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

$terms = get_the_terms( $post->ID, 'visits' );
                        
if ( $terms && ! is_wp_error( $terms ) ) : 
  echo join( ',', wp_list_pluck( $terms, 'name' ) );
endif;

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;
    }
    $terms_list = join( ", ", $visits_name );
    echo $terms_list;
endif;
                        

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;

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;
    }
    $terms_list = join( ", ", $visits_name );
    echo $terms_list;
endif;
                        

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;
improved answer
Source Link
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;
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;

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;

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;
    }
    $terms_list = join( ", ", $visits_name );
    echo $terms_list;
endif;
                        

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;
fixed unclosed if and added an example using wp_list_pluck.
Source Link
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 $terms_list;join( ',', wp_list_pluck( $terms, 'name' ) );
endif;

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;
    }
                        
    $terms_list = join( ", ", $visits_name );
    echo $terms_list;

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;
Source Link
RRikesh
  • 5.7k
  • 4
  • 31
  • 45
Loading