bbp_admin_repair_topic_meta()
Recaches the topic for each post
Description
Return
(array) An array of the status code and the message
Source
File: bp-forums/admin/tools.php
function bbp_admin_repair_topic_meta() {
global $wpdb;
$statement = __( 'Recalculating the discussion for each post … %s', 'buddyboss' );
$result = __( 'Failed!', 'buddyboss' );
// First, delete everything.
if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) )
return array( 1, sprintf( $statement, $result ) );
// Next, give all the topics with replies the ID their last reply.
if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
( SELECT `topic`.`ID`, '_bbp_topic_id', `topic`.`ID`
FROM `$wpdb->posts`
AS `topic`
WHERE `topic`.`post_type` = 'topic'
GROUP BY `topic`.`ID` );" ) ) )
return array( 3, sprintf( $statement, $result ) );
// Next, give all the topics with replies the ID their last reply.
if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
( SELECT `reply`.`ID`, '_bbp_topic_id', `topic`.`ID`
FROM `$wpdb->posts`
AS `reply`
INNER JOIN `$wpdb->posts`
AS `topic`
ON `reply`.`post_parent` = `topic`.`ID`
WHERE `topic`.`post_type` = 'topic'
AND `reply`.`post_type` = 'reply'
GROUP BY `reply`.`ID` );" ) ) )
return array( 4, sprintf( $statement, $result ) );
// Complete results
return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3876) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.