bbp_update_forum_topic_count( int $forum_id )

Adjust the total topic count of a forum


Description Description


Parameters 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?


Top ↑

Return Return

(int) Forum topic count


Top ↑

Source Source

File: includes/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 ( $children as $child ) {
			$children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive
		}
	}

	// Get total topics for this forum
	$topics = bbp_get_public_child_count( $forum_id, bbp_get_topic_post_type() );

	// Calculate total topics in this forum
	$total_topics = (int) ( $topics + $children_topic_count );

	// Update the count
	update_post_meta( $forum_id, '_bbp_topic_count',       $topics       );
	update_post_meta( $forum_id, '_bbp_total_topic_count', $total_topics );

	// Filter & return
	return (int) apply_filters( 'bbp_update_forum_topic_count', $total_topics, $forum_id );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.