bbp_update_topic_reply_count_hidden

Adjust the total hidden reply count of a topic (hidden includes trashed and spammed replies).

Description

(int) bbp_update_topic_reply_count_hidden( (int) $topic_id = 0, (int) $reply_count = 0 ); 

Returns (int)

Topic hidden reply count

Parameters (2)

0. $topic_id — Optional. (int)
Topic id to update
1. $reply_count — Optional. (int)
Set the reply count manually

Usage

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

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) { 
  2. global $wpdb; 
  3.  
  4. // If it's a reply, then get the parent (topic id) 
  5. if ( bbp_is_reply( $topic_id ) ) { 
  6. $topic_id = bbp_get_reply_topic_id( $topic_id ); 
  7. } else { 
  8. $topic_id = bbp_get_topic_id( $topic_id ); 
  9.  
  10. // Get replies of topic 
  11. if ( empty( $reply_count ) ) { 
  12. $post_status = "'" . implode( "', '", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "'"; 
  13. $reply_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';", $topic_id, bbp_get_reply_post_type() ) ); 
  14.  
  15. update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $reply_count ); 
  16.  
  17. return apply_filters( 'bbp_update_topic_reply_count_hidden', (int) $reply_count, $topic_id );