Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Freshness is way off

@webcreations907

Participant

The below should update the “Topic” page and the main “Forum” page.

Once you add the code, you’ll have to add a reply to a topic for it to update. Or run the forum repair Robin W mentioned above.

Add the below code to your functions.php file of your theme (preferably child theme), or use the code snippet plugin.


if(!function_exists('ticket3297_bbpress_update_latest_activity')){
	function ticket3297_bbpress_update_latest_activity( $reply_id, $topic_id, $forum_id ){
		
		$new_time = get_post_field( 'post_date', $reply_id );
		
		if ( ! empty( $new_time ) ) {
			update_post_meta( $forum_id, '_bbp_last_active_time', $new_time );
		}
		update_post_meta( $forum_id, '_bbp_last_active_id', $reply_id);
		update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id );

		$forum_obj = get_post( $forum_id );
		if( $forum_obj && $forum_obj->post_parent !== 0 && bbp_is_forum_category( $forum_obj->post_parent ) ){
		
			update_post_meta( $forum_obj->post_parent, '_bbp_last_active_id', $reply_id );
			update_post_meta( $forum_obj->post_parent, '_bbp_last_reply_id', $reply_id );
			if ( ! empty( $new_time ) ) {
				update_post_meta( $forum_obj->post_parent, '_bbp_last_active_time', $new_time );
			}
		}

	}
	add_action( 'bbp_new_reply', 'ticket3297_bbpress_update_latest_activity',10,3 );
}

if(!function_exists('ticket3297_bbpress_delete_update_latest_activity')){
	function ticket3297_bbpress_delete_update_latest_activity(){
			$reply_id = bbp_forum_query_last_reply_id();
			
			ticket3297_bbpress_update_latest_activity( $reply_id, bbp_get_reply_topic_id( $reply_id ), bbp_get_reply_forum_id( $reply_id ) );

	}
	add_action('bbp_deleted_reply','ticket3297_bbpress_delete_update_latest_activity');
	add_action('bbp_trashed_reply','ticket3297_bbpress_delete_update_latest_activity');
}

That should run when replying, deleting, and trashing replies.

Skip to toolbar