On search results pages I would like to show a tag list collected from other posts that are listed for the seach result.

// same tag should not be listed twice

And for the taxonomy pages again; tags of other post that are listed for the current tag.

I tried some experiments with get_the_tags(array(post ids)) but couldn't make it work.

Thank you,

1 Answer 1


You can use simple solution below. You need to use this function in the loop. You can collect tags/categories in an array or show tags/categories under the posts.

$terms = get_the_terms( get_the_ID(), 'category' );
  if ( $terms && ! is_wp_error( $terms ) ) : 
   $catlinks = array();
    foreach ( $terms as $term ) {
      $catlinks[] = $term->name;

$catso = join( ", ", $catlinks );

<p class="list-of-cats">
    <?php printf( esc_html__( 'Categories: <span>%s</span>', 'textdomain' ), esc_html( $catso ) ); ?>

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.