bbp_update_topic_anonymous_reply_count( int $topic_id )

Adjust the total anonymous reply count of a topic

Description

Parameters

$topic_id

(Optional) Topic id to update

Return

(int) Anonymous reply count

Source

File: bp-forums/topics/functions.php

2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
function bbp_update_topic_anonymous_reply_count( $topic_id = 0 ) {
    global $wpdb;
 
    // If it's a reply, then get the parent (topic id)
    if ( bbp_is_reply( $topic_id ) ) {
        $topic_id = bbp_get_reply_topic_id( $topic_id );
    } elseif ( bbp_is_topic( $topic_id ) ) {
        $topic_id = bbp_get_topic_id( $topic_id );
    } else {
        return;
    }
 
    $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
 
    update_post_meta( $topic_id, '_bbp_anonymous_reply_count', (int) $anonymous_replies );
 
    return apply_filters( 'bbp_update_topic_anonymous_reply_count', (int) $anonymous_replies, $topic_id );
}

Changelog

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