bbp_admin_repair_forum_reply_count

Recount forum replies.

Description

(array) bbp_admin_repair_forum_reply_count(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_forum_reply_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_forum_reply_count(); 
  7.  

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_repair_forum_reply_count() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Counting the number of replies in each forum… %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6.  
  7. // Post type 
  8.  
  9. // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum 
  10. $sql_delete = "DELETE `postmeta` FROM `{$wpdb->postmeta}` AS `postmeta` 
  11. LEFT JOIN `{$wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 
  12. WHERE `posts`.`post_type` = '{$fpt}' 
  13. AND `postmeta`.`meta_key` = '_bbp_reply_count' 
  14. OR `postmeta`.`meta_key` = '_bbp_total_reply_count'"; 
  15.  
  16. if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 
  17. return array( 1, sprintf( $statement, $result ) ); 
  18.  
  19. // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum 
  20. $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 
  21. if ( !empty( $forums ) ) { 
  22. foreach ( $forums as $forum ) { 
  23. } else { 
  24. return array( 2, sprintf( $statement, $result ) ); 
  25.  
  26. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );