Is there a (simple?) way to test if a taxonomy has at least one tag that is used on more than one page?
I know how to see if there are any terms in a given taxonomy on the current page. And I know how to see if a given term on the current page is tagged on more than just the current page. Here is my code that works as written:
if( ! empty( wp_get_object_terms($post->ID, 'topic') ) ) {
echo '<p>Explore other posts with these topics:</p><div class="topic-list"><p class="meta-tag-list">';
$terms = wp_get_object_terms($post->ID, 'topic');
foreach ($terms as $key => $term) {
if( $term->count > 1 ) { // if the count is > 1, output, if not, then nothing will happen
$link = get_term_link( $term->term_id );
echo '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}
}
echo '</p></div> <!-- topic-list -->';
}
But my first if statement just check to see if there are terms for that taxonomy on that page. But what it really needs to do is check if there is at least one term that has at least two pages tagged.
Because if there is a term for the current page, but that page is the only page for the term, then the first if statement executes and my heading "Explore other posts with these topics:" displays, but the second if statement doesn't execute. So I end up with a heading with nothing under it.
I think if the average number of total pages tagged with all terms is greater than one (total number of all pages tagged by terms this page is tagged with divided by total number of tags on this page) then that would meet the criterion. Is there an easy way to test that, or is there just a better way to do this?