bbp_update_forum_topic_count_hidden( int $forum_id, int $topic_count = false )

Adjust the total hidden topic count of a forum (hidden includes trashed, spammed and pending topics)


Description Description


Parameters Parameters

$forum_id

(Optional) Topic id to update.

$topic_count

(Optional) Set the topic count manually.

Default value: false


Top ↑

Return Return

(int) Topic hidden topic count


Top ↑

Source Source

File: includes/forums/functions.php

function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = false ) {

	// If topic_id was passed as $forum_id, then get its forum
	if ( bbp_is_topic( $forum_id ) ) {
		$topic_id = bbp_get_topic_id( $forum_id );
		$forum_id = bbp_get_topic_forum_id( $topic_id );

	// $forum_id is not a topic_id, so validate and proceed
	} else {
		$forum_id = bbp_get_forum_id( $forum_id );
	}

	// Can't update what isn't there
	if ( ! empty( $forum_id ) ) {

		// Get topics of forum
		if ( ! is_int( $topic_count ) ) {
			$query = new WP_Query( array(
				'fields'         => 'ids',
				'post_parent'    => $forum_id,
				'post_status'    => bbp_get_non_public_topic_statuses(),
				'post_type'      => bbp_get_topic_post_type(),
				'posts_per_page' => -1,

				// Performance
				'nopaging'               => true,
				'suppress_filters'       => true,
				'update_post_term_cache' => false,
				'update_post_meta_cache' => false,
				'ignore_sticky_posts'    => true,
				'no_found_rows'          => true
			) );
			$topic_count = $query->post_count;
			unset( $query );
		}

		$topic_count = (int) $topic_count;

		// Update the count
		update_post_meta( $forum_id, '_bbp_topic_count_hidden', $topic_count );
	}

	// Filter & return
	return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', $topic_count, $forum_id );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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