How to Display Tags from a Specific category (or NOT display them)
-
So, I’ve seen some questions about this and I couldn’t find the answer here on WordPress.org foruns, so I went up to research my own solution.
Sometimes, you want the
wp_tag_cloud()
to display only tags from a specific category or not to display them.There’s no easy option buil-in the function that allows us to easily achieve this result. But there are those options ‘include’ and ‘exclude’ on the parameters array.
So, what if, we listed all tags from a category first and just then we called the
wp_cloud_tag()
function using the tags we just retrieved from the category?Well, that’s exactly how I achieved this result and here you can find it:
query_posts('category_name=desired-category'); //Search for the posts under the category you wish to retrieve the tags for. if (have_posts()) : while (have_posts()) : the_post(); $post_tags = get_the_tags(); if ($post_tags) { foreach($posttags as $tag) { $all_tags[] = $tag->term_id; //save the tag term_id in an array } } endwhile; endif; $tags_ = array_unique($all_tags); //remove the duplicates id wp_tag_cloud(array('include' => $tags_)); //Pass the tags we found to the function
Hop this helped someone out as it helped me 🙂
- The topic ‘How to Display Tags from a Specific category (or NOT display them)’ is closed to new replies.