bbp_update_topic_last_active_id( int $topic_id, int $active_id )

Update the topic with the last active post ID

Description

Parameters

$topic_id

(Optional) Topic id to update

$active_id

(Optional) active id

Return

(int) Active id

Source

File: bp-forums/topics/functions.php

function bbp_update_topic_last_active_id( $topic_id = 0, $active_id = 0 ) {

	// 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 );
	} else {
		$topic_id = bbp_get_topic_id( $topic_id );
	}

	if ( empty( $active_id ) ) {
		$active_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( $active_id ) || !bbp_is_reply( $active_id ) ) {
		$active_id = $topic_id;
	}

	// Update only if published
	if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) {
		update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id );
	}

	return apply_filters( 'bbp_update_topic_last_active_id', (int) $active_id, $topic_id );
}

Changelog

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