Try adding this PHP Snippet – it will register a new shortcode function ie. you can still use the old shortcode for posts:
function category_specific_tag_cloud( $atts ) {
$atts = shortcode_atts( array(
'category' => null
), $atts );
// get the category by slug.
$category = get_category_by_slug( $atts['category'] );
$category_id = $category->cat_ID;
$query_args = array( 'cat' => $category_id, 'posts_per_page' => -1 );
$custom_query = new WP_Query( $query_args );
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags[] = $tag->term_id;
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);
$args = array(
'echo' => false,
'smallest' => 10,
'largest' => 30,
'unit' => 'px',
'number' => 30,
'format' => 'flat',
'order' => 'count',
'include' => $tags_str
);
wp_reset_postdata();
return wp_tag_cloud($args);
}
add_shortcode( 'tagcloudbycategory', 'category_specific_tag_cloud' );
You can then add this shortcode to any Page:
[tagcloudbycategory category="slug"]
Simply change the slug
to that of the category you want displayed.