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

(int) (Optional) Topic id to update

$reply_id

(int) (Optional) Reply id

Return

(int) Reply id

Source

File: bp-forums/topics/functions.php

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.