bbp_update_topic_last_reply_id( int $topic_id, int $reply_id )

Update the topic with the most recent reply ID

Description

Parameters

$topic_id

(Optional) Topic id to update

$reply_id

(Optional) Reply id

Return

(int) Reply id

Source

File: bp-forums/topics/functions.php

2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
function bbp_update_topic_last_reply_id( $topic_id = 0, $reply_id = 0 ) {
 
    // If it's a reply, then get the parent (topic id)
    if ( empty( $reply_id ) && bbp_is_reply( $topic_id ) ) {
        $reply_id = bbp_get_reply_id( $topic_id );
        $topic_id = bbp_get_reply_topic_id( $reply_id );
    } else {
        $reply_id = bbp_get_reply_id( $reply_id );
        $topic_id = bbp_get_topic_id( $topic_id );
    }
 
    if ( empty( $reply_id ) ) {
        $reply_id = bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() );
    }
 
    // Adjust last_id's based on last_reply post_type
    if ( empty( $reply_id ) || !bbp_is_reply( $reply_id ) ) {
        $reply_id = 0;
    }
 
    // Update if reply is published
    if ( bbp_is_reply_published( $reply_id ) ) {
        update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id );
    }
 
    return apply_filters( 'bbp_update_topic_last_reply_id', (int) $reply_id, $topic_id );
}

Changelog

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