bbp_update_forum_topic_count_hidden

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

Description

(int) bbp_update_forum_topic_count_hidden( (int) $forum_id = 0, (int) $topic_count = 0 ); 

Returns (int)

Topic hidden topic count

Parameters (2)

0. $forum_id — Optional. (int)
Topic id to update
1. $topic_count — Optional. (int)
Set the topic count manually

Usage

  1. if ( !function_exists( 'bbp_update_forum_topic_count_hidden' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // Optional. Topic id to update 
  5. $forum_id = -1; 
  6.  
  7. // Optional. Set the topic count manually 
  8. $topic_count = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_forum_topic_count_hidden($forum_id, $topic_count); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/forums/functions.php  
  1. function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) { 
  2. global $wpdb; 
  3.  
  4. // If topic_id was passed as $forum_id, then get its forum 
  5. if ( bbp_is_topic( $forum_id ) ) { 
  6. $topic_id = bbp_get_topic_id( $forum_id ); 
  7. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  8.  
  9. // $forum_id is not a topic_id, so validate and proceed 
  10. } else { 
  11. $forum_id = bbp_get_forum_id( $forum_id ); 
  12.  
  13. // Can't update what isn't there 
  14. if ( !empty( $forum_id ) ) { 
  15.  
  16. // Get topics of forum 
  17. if ( empty( $topic_count ) ) { 
  18. $post_status = "'" . implode( "', '", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "'"; 
  19. $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() ) ); 
  20.  
  21. // Update the count 
  22. update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $topic_count ); 
  23.  
  24. return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id );