bbp_update_forum_topic_count( int $forum_id )
Adjust the total topic count of a forum
Description
Parameters
- $forum_id
-
(Optional) Forum id or topic id. It is checked whether it is a topic or a forum. If it's a topic, its parent, i.e. the forum is automatically retrieved.
- $total_count
-
(Optional) To return the total count or normal count?
Return
(int) Forum topic count
Source
File: bp-forums/forums/functions.php
function bbp_update_forum_topic_count( $forum_id = 0 ) { $forum_id = bbp_get_forum_id( $forum_id ); $children_topic_count = 0; // Loop through subforums and add together forum topic counts $children = bbp_forum_query_subforum_ids( $forum_id ); if ( !empty( $children ) ) { foreach ( (array) $children as $child ) { $children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive } } // Get total topics for this forum $topics = (int) count( bbp_forum_query_topic_ids( $forum_id ) ); // Calculate total topics in this forum $total_topics = $topics + $children_topic_count; // Update the count update_post_meta( $forum_id, '_bbp_topic_count', (int) $topics ); update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topics ); return (int) apply_filters( 'bbp_update_forum_topic_count', (int) $total_topics, $forum_id ); }
Changelog
Version | Description |
---|---|
bbPress (r2464) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.