bb_recount_topic_voices

The BuddyPress bb recount topic voices function.

Description

bb_recount_topic_voices(); 

Usage

  1. if ( !function_exists( 'bb_recount_topic_voices' ) ) { 
  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_voices(); 
  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_voices() 
  2. global $bbdb; 
  3.  
  4. $statement = __( 'Counting the number of voices in each topic… %s' ); 
  5. $result = __( 'Failed!' ); 
  6.  
  7. $sql_delete = "DELETE FROM `$bbdb->meta` WHERE `object_type` = 'bb_topic' AND `meta_key` = 'voices_count';"; 
  8. if ( is_wp_error( $bbdb->query( $sql_delete ) ) ) { 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. $sql = "INSERT INTO `$bbdb->meta` (`object_type`, `object_id`, `meta_key`, `meta_value`) (SELECT 'bb_topic', `topic_id`, 'voices_count', COUNT(DISTINCT `poster_id`) as `meta_value` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `topic_id`);"; 
  12. if ( is_wp_error( $bbdb->query( $sql ) ) ) { 
  13. return array( 2, sprintf( $statement, $result ) ); 
  14.  
  15. $result = __( 'Complete!' ); 
  16. return array( 0, sprintf( $statement, $result ) );