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

1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
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

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.