Get tags based on the wordpress category

June 27, 2009 · Print This Article

Althought WordPress allow you to do lots of things by default, but how to retrieve tags based on the category?

Just paste following code wherever you need to display the list of tags that are specific to a particular category.

Note: You can replace the category name on line two.


if (have_posts()) : 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; endif;

$tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
echo '<pre>'.print_r($tags_arr, true).'</pre>'; //OUTPUT FINAL TAGS FROM CATEGORY


Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.