bbp_admin_repair_forum_meta()
Recaches the forum 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_forum_meta() {
global $wpdb;
$statement = __( 'Recalculating the forum 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_forum_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 `forum`.`ID`, '_bbp_forum_id', `forum`.`post_parent`
FROM `$wpdb->posts`
AS `forum`
WHERE `forum`.`post_type` = 'forum'
GROUP BY `forum`.`ID` );" ) ) )
return array( 2, 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_forum_id', `topic`.`post_parent`
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_forum_id', `topic`.`post_parent`
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.