bbp_update_topic_reply_count( int $topic_id, int $reply_count )

Adjust the total reply count of a topic

Description

Parameters

$topic_id

(int) (Optional) Topic id to update

$reply_count

(int) (Optional) Set the reply count manually.

Return

(int) Topic reply count

Source

File: bp-forums/topics/functions.php

function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = 0 ) {

	// If it's a reply, then get the parent (topic id)
	if ( bbp_is_reply( $topic_id ) ) {
		$topic_id = bbp_get_reply_topic_id( $topic_id );
	} else {
		$topic_id = bbp_get_topic_id( $topic_id );
	}

	// Get replies of topic if not passed
	if ( empty( $reply_count ) ) {
		$reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() );
	}

	update_post_meta( $topic_id, '_bbp_reply_count', (int) $reply_count );

	return apply_filters( 'bbp_update_topic_reply_count', (int) $reply_count, $topic_id );
}

Changelog

Changelog
Version Description
bbPress (r2467) 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.