Count topics with specific tag
I need your advice on how to count the number of topics associated with a specific tag. Is there a function already available or do I have to write my own? I’m needing this piece of data to include in WP-REST response.
Any help would be greatly appreciated. Thanks.
I think bbPress just uses the code from WordPress since the topic tag clouds code is close to WordPress’s version for regular posts.
You can see the tag cloud on hover displays the number of topics.
I tried searching what it was, but couldn’t really pinpoint the exact function.
If it can help, check shortcodes. The 2nd one could be your starting point:
[bbp-topic-tags] – Display a tag cloud of all topic tags.
[bbp-single-tag id=$tag_id] – Display a list of all topics associated with a specific tag. eg. [bbp-single-tag id=64]
With a combination of two methods, I was able to get the number of topics per tag. These methods query the taxonomies of bbPress’ topic-tag:
$tagList = get_the_terms($post->ID, bbp_get_topic_tag_tax_id());
The output of $tagList is as follow and ‘count’ is what i’m interested in:
Hope this helps others.
This topic is quite old but it seems to be the only one about displaying tagged topics count. How would you implement the query to count topic tags? Is it possible to create a custom shortcode to show the tag count? Any help with this would be greatly appreciated, thanks!
- You must be logged in to reply to this topic.