bbp_bump_forum_topic_count

Bump the total topic count of a forum.

Description

(int) bbp_bump_forum_topic_count( (int) $forum_id = 0, (int) $difference = 1, (bool) $update_ancestors = true ); 

Returns (int)

Forum topic count

Parameters (3)

0. $forum_id — Optional. (int)
Forum id.
1. $difference — Optional. (int) => 1
Default 1
2. $update_ancestors — Optional. (bool) => true
Default true

Usage

  1. if ( !function_exists( 'bbp_bump_forum_topic_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // Optional. Forum id. 
  5. $forum_id = -1; 
  6.  
  7. // Optional. Default 1 
  8. $difference = 1; 
  9.  
  10. // Optional. Default true 
  11. $update_ancestors = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bbp_bump_forum_topic_count($forum_id, $difference, $update_ancestors); 
  15.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) { 
  2.  
  3. // Get some counts 
  4. $forum_id = bbp_get_forum_id( $forum_id ); 
  5. $topic_count = bbp_get_forum_topic_count( $forum_id, false, true ); 
  6. $total_topic_count = bbp_get_forum_topic_count( $forum_id, true, true ); 
  7.  
  8. // Update this forum id 
  9. update_post_meta( $forum_id, '_bbp_topic_count', (int) $topic_count + (int) $difference ); 
  10. update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topic_count + (int) $difference ); 
  11.  
  12. // Check for ancestors 
  13. if ( true === $update_ancestors ) { 
  14.  
  15. // Get post ancestors 
  16. $forum = get_post( $forum_id ); 
  17. $ancestors = get_post_ancestors( $forum ); 
  18.  
  19. // If has ancestors, loop through them... 
  20. if ( !empty( $ancestors ) ) { 
  21. foreach ( (array) $ancestors as $parent_forum_id ) { 
  22.  
  23. // Get forum counts 
  24. $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id, false, true ); 
  25. $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true, true ); 
  26.  
  27. // Update counts 
  28. update_post_meta( $parent_forum_id, '_bbp_topic_count', (int) $parent_topic_count + (int) $difference ); 
  29. update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) $parent_total_topic_count + (int) $difference ); 
  30.  
  31. return (int) apply_filters( 'bbp_bump_forum_topic_count', (int) $total_topic_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );