bbp_update_forum( mixed $args = '' )

Updates the counts of a forum.

Description

This calls a few internal functions that all run manual queries against the database to get their results. As such, this function can be costly to run but is necessary to keep everything accurate.

Parameters

$args

(Optional) Supports these arguments: - forum_id: Forum id - last_topic_id: Last topic id - last_reply_id: Last reply id - last_active_id: Last active post id - last_active_time: last active time

Default value: ''

Source

File: bp-forums/forums/functions.php

1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
function bbp_update_forum( $args = '' ) {
 
    // Parse arguments against default values
    $r = bbp_parse_args( $args, array(
        'forum_id'           => 0,
        'post_parent'        => 0,
        'last_topic_id'      => 0,
        'last_reply_id'      => 0,
        'last_active_id'     => 0,
        'last_active_time'   => 0,
        'last_active_status' => bbp_get_public_status_id()
    ), 'update_forum' );
 
    // Last topic and reply ID's
    bbp_update_forum_last_topic_id( $r['forum_id'], $r['last_topic_id'] );
    bbp_update_forum_last_reply_id( $r['forum_id'], $r['last_reply_id'] );
 
    // Active dance
    $r['last_active_id'] = bbp_update_forum_last_active_id( $r['forum_id'], $r['last_active_id'] );
 
    // If no active time was passed, get it from the last_active_id
    if ( empty( $r['last_active_time'] ) ) {
        $r['last_active_time'] = get_post_field( 'post_date', $r['last_active_id'] );
    }
 
    if ( bbp_get_public_status_id() === $r['last_active_status'] ) {
        bbp_update_forum_last_active_time( $r['forum_id'], $r['last_active_time'] );
    }
 
    // Counts
    bbp_update_forum_subforum_count    ( $r['forum_id'] );
    bbp_update_forum_reply_count       ( $r['forum_id'] );
    bbp_update_forum_topic_count       ( $r['forum_id'] );
    bbp_update_forum_topic_count_hidden( $r['forum_id'] );
 
    // Update the parent forum if one was passed
    if ( !empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) {
        bbp_update_forum( array(
            'forum_id'    => $r['post_parent'],
            'post_parent' => get_post_field( 'post_parent', $r['post_parent'] )
        ) );
    }
}

Changelog

Changelog
Version Description
bbPress (r2908) 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.