bb_recount_topic_posts

The BuddyPress bb recount topic posts function.

Description

bb_recount_topic_posts(); 

Usage

  1. if ( !function_exists( 'bb_recount_topic_posts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-recount.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_recount_topic_posts(); 
  7.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-recount.php  
  1. function bb_recount_topic_posts() 
  2. global $bbdb; 
  3.  
  4. $statement = __( 'Counting the number of posts in each topic… %s' ); 
  5. $result = __( 'Failed!' ); 
  6.  
  7. $sql = "INSERT INTO `$bbdb->topics` (`topic_id`, `topic_posts`) (SELECT `topic_id`, COUNT(`post_status`) as `topic_posts` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `topic_id`) ON DUPLICATE KEY UPDATE `topic_posts` = VALUES(`topic_posts`);"; 
  8. if ( is_wp_error( $bbdb->query( $sql ) ) ) { 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. $result = __( 'Complete!' ); 
  12. return array( 0, sprintf( $statement, $result ) );