0
<p> <?php $terms = wp_get_post_terms($post->ID, 'sublocation');
    if ($terms) {
       foreach ($terms as $term) {
       $out[] = '<a class="' .$term->slug .'" href="' .get_term_link( $term->slug, 'sublocation') .'">' .$term->name .'</a>';
       }
    echo join( ', ', $out );
    } ?>
</p>


 <p>TYPE OF MUSIC: <?php $terms = get_the_terms($post->ID, 'music'); 
      if ($terms) { foreach ($terms as $term) {
      $out[] = '<a class="' .$term->slug .'" href="' .get_term_link( $term->slug, 'music') .'">' .$term->name .'</a>';
      } echo join( ', ', $out ); 
      }?>
</p>

<p>TYPE OF PUB: <?php $terms = wp_get_post_terms($post->ID, 'pub');
      if ( !empty( $terms ) ) {
       foreach ($terms as $term) {
         $out[] = '<a class="' .$term->slug .'" href="' .get_term_link( $term->slug, 'pub') .'">' .$term->name .'</a>';
       }
        echo join( ' ', $out );
       } ?>
</p>

After calling this i am getting like this

enter image description here

See above image the categories are showing same on each type.

Please how can i fix this

1

1 Answer 1

1
<p> <?php
$terms = wp_get_post_terms ( $post -> ID , 'sublocation' ) ;
if ( $terms ) {
    foreach ( $terms as $term ) {
        $out[ ] = '<a class="' . $term -> slug . '" href="' . get_term_link ( $term -> slug , 'sublocation' ) . '">' . $term -> name . '</a>' ;
    }
    echo join ( ', ' , $out ) ;
}
?>
</p>

<p>TYPE OF MUSIC: <?php
    $terms = get_the_terms ( $post -> ID , 'music' ) ;
    if ( $terms ) {
        $out = array ( ) ; // reInitialise
        foreach ( $terms as $term ) {
            $out[ ] = '<a class="' . $term -> slug . '" href="' . get_term_link ( $term -> slug , 'music' ) . '">' . $term -> name . '</a>' ;
        }
        echo join ( ', ' , $out ) ;
    }
?>
</p>

<p>TYPE OF PUB: <?php
    $terms = wp_get_post_terms ( $post -> ID , 'pub' ) ;
    if ( ! empty ( $terms ) ) {
        $out = array ( ) ; // reInitialise
        foreach ( $terms as $term ) {
            $out[ ] = '<a class="' . $term -> slug . '" href="' . get_term_link ( $term -> slug , 'pub' ) . '">' . $term -> name . '</a>' ;
        }
        echo join ( ' ' , $out ) ;
    }
?>
</p>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.