I need to print all the tags links which i used in custom post type.

Name of Custom post type= mobile

Taxonomy tag slug = brand

  $terms = get_terms( 'brand' );
  $count = count( $terms );
   if ( $count > 0 ) {
      echo '<ul>';
      foreach ( $terms as $term ) {?>

      <a href="<?php the_permalink(); ?>"><?php echo '<p>' . $term->name . '</p>';?> </a>

 <?php }
  echo '</ul>';

With this code i successfully print all tags name. But unable to make these links.

How to print tags with link to view all post related to that tag??

1 Answer 1


To get the link of any term meta, use get_term_link() function. https://developer.wordpress.org/reference/functions/get_the_terms/

So replace the_permalink() to echo get_term_link($term->term_id); inside your loop.

<a href="<?php  echo get_term_link($term->term_id); ?>"><?php echo '<p>' . $term->name . '</p>';?> </a>

This link will redirect to tag archive page. Hope this help!

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.