bbp_update_forum_topic_count_hidden( int $forum_id, int $topic_count )
Adjust the total hidden topic count of a forum (hidden includes trashed and spammed topics)
Description
Parameters
- $forum_id
-
(Optional) Topic id to update
- $topic_count
-
(Optional) Set the topic count manually
Return
(int) Topic hidden topic count
Source
File: bp-forums/forums/functions.php
function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) { global $wpdb; // 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 ( empty( $topic_count ) ) { $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "'"; $topic_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) ); } // Update the count update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $topic_count ); } return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id ); }
Changelog
Version | Description |
---|---|
bbPress (r2888) | 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.