Want to show all tags related to a category in WordPress? Showing all related tags can help users find relevant content that they might be interested in. In this article, we’ll show you how to show all tags related to a category on your WordPress site.
Instructions:
All you have to do is add this code to your template file where you want the tags to be displayed. If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
<?php $project_query = query_posts('category_name=Real estate marketing'); while (have_posts()) : the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags_arr[] = $tag -> name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique } } endwhile; $tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES foreach( $tags_arr as $tag ): $el = get_term_by('name', $tag, 'post_tag'); $arr[] = '"tag-'.$el->slug.'"'; ?> <span><a href="<?php echo bloginfo('url'); ?>/tag/<?php echo $el->slug; ?>" id="taglink-tag-<?php echo $el->slug; ?>" rel="tag-<?php echo $el->slug; ?>"><?php echo $el->name; ?></a> <span class="slash">, </span></span> <?php endforeach; ?>
If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.
Comments Leave a Reply