bbp_admin_repair_topic_voice_count

Recount topic voices.

Description

(array) bbp_admin_repair_topic_voice_count(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_topic_voice_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/tools.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_admin_repair_topic_voice_count(); 
  7.  

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_repair_topic_voice_count() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Counting the number of voices in each topic… %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6.  
  7. $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_voice_count';"; 
  8. if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. // Post types and status 
  12.  
  13. $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 
  14. SELECT `postmeta`.`meta_value`, '_bbp_voice_count', COUNT(DISTINCT `post_author`) as `meta_value` 
  15. FROM `{$wpdb->posts}` AS `posts` 
  16. LEFT JOIN `{$wpdb->postmeta}` AS `postmeta` 
  17. ON `posts`.`ID` = `postmeta`.`post_id` 
  18. AND `postmeta`.`meta_key` = '_bbp_topic_id' 
  19. WHERE `posts`.`post_type` IN ( '{$tpt}', '{$rpt}' ) 
  20. AND `posts`.`post_status` IN ( '{$pps}', '{$cps}' ) 
  21. AND `posts`.`post_author` != '0' 
  22. GROUP BY `postmeta`.`meta_value`);"; 
  23.  
  24. if ( is_wp_error( $wpdb->query( $sql ) ) ) 
  25. return array( 2, sprintf( $statement, $result ) ); 
  26.  
  27. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );