With an array containing the post IDs its easy
$post_ids = array( 167, 774, 787, 358 );
$tag_all = array();
foreach ( $post_ids as $post_id ) {
$tags = wp_get_post_tags( $post_id, array() );
foreach ( $tags as $tag )
array_push( $tag_all, $tag->name );
}
$result = array_count_values($tag_all);
arsort( $result );
$result = array_slice( $result, 0, 5 );
echo '<ol>';
foreach ( $result as $tag => $count ) {
printf( '<li>%s (%d)</li>', $tag, $count );
}
echo '</ol>';
Walk over the post IDs, get the tags of each post. Add the tags to a result array ($tag_all
). Then counting the values (array_count_values()
), this gives you an array with key => value
(key
= tag, value
= count). Now just sorting the result array (arsort()
) and get the first 5 elements (array_slice()
).
Create a nice outpout and finish.