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
if ( !function_exists( 'bbp_admin_repair_topic_voice_count' ) ) { require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/tools.php'; } // NOTICE! Understand what this does before running. $result = bbp_admin_repair_topic_voice_count();
Defined (1)
The function is defined in the following location(s).
- /includes/admin/tools.php
- function bbp_admin_repair_topic_voice_count() {
- global $wpdb;
- $statement = __( 'Counting the number of voices in each topic… %s', bbpress );
- $result = __( 'Failed!', bbpress );
- $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_voice_count';";
- if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
- return array( 1, sprintf( $statement, $result ) );
- // Post types and status
- $tpt = bbp_get_topic_post_type();
- $rpt = bbp_get_reply_post_type();
- $pps = bbp_get_public_status_id();
- $cps = bbp_get_closed_status_id();
- $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (
- SELECT `postmeta`.`meta_value`, '_bbp_voice_count', COUNT(DISTINCT `post_author`) as `meta_value`
- FROM `{$wpdb->posts}` AS `posts`
- LEFT JOIN `{$wpdb->postmeta}` AS `postmeta`
- ON `posts`.`ID` = `postmeta`.`post_id`
- AND `postmeta`.`meta_key` = '_bbp_topic_id'
- WHERE `posts`.`post_type` IN ( '{$tpt}', '{$rpt}' )
- AND `posts`.`post_status` IN ( '{$pps}', '{$cps}' )
- AND `posts`.`post_author` != '0'
- GROUP BY `postmeta`.`meta_value`);";
- if ( is_wp_error( $wpdb->query( $sql ) ) )
- return array( 2, sprintf( $statement, $result ) );
- return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );
- }