Si possono filtrare i tag di WordPress per creare una tag cloud personalizzata.
La soluzione รจ la seguente:
function my_tag_cloud() {
$args = array( 'posts_per_page' => -1, 'category__in' => array( 7, 15, 20 ) );
$loop = new WP_Query( $args );
$tags = array();
while( $loop->have_posts() ) {
$loop->the_post();
$id = get_the_ID();
$tag_ids = wp_get_post_tags( $id, array( 'fields' => 'ids' ) );
foreach( $tag_ids as $tag_id ) {
$tags[] = $tag_id;
}
}
wp_reset_postdata();
$tags_in = array_unique( $tags );
$tags_arg = array( 'echo' => false, 'include' => implode(',', $tags_in ) );
$html = '<div class="tagcloud">' . wp_tag_cloud( $tags_arg ) . '</div>';
return $html;
}
add_shortcode( 'my-tag-cloud', 'my_tag_cloud' );