bbp_update_topic_last_active_id

Update the topic with the last active post ID.

Description

(int) bbp_update_topic_last_active_id( (int) $topic_id = 0, (int) $active_id = 0 ); 

Returns (int)

Active id

Parameters (2)

0. $topic_id — Optional. (int)
Topic id to update
1. $active_id — Optional. (int)
active id

Usage

  1. if ( !function_exists( 'bbp_update_topic_last_active_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/functions.php'; 
  3.  
  4. // Optional. Topic id to update 
  5. $topic_id = -1; 
  6.  
  7. // Optional. active id 
  8. $active_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_topic_last_active_id($topic_id, $active_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/topics/functions.php  
  1. function bbp_update_topic_last_active_id( $topic_id = 0, $active_id = 0 ) { 
  2.  
  3. // If it's a reply, then get the parent (topic id) 
  4. if ( bbp_is_reply( $topic_id ) ) { 
  5. $topic_id = bbp_get_reply_topic_id( $topic_id ); 
  6. } else { 
  7. $topic_id = bbp_get_topic_id( $topic_id ); 
  8.  
  9. if ( empty( $active_id ) ) { 
  10. $active_id = bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ); 
  11.  
  12. // Adjust last_id's based on last_reply post_type 
  13. if ( empty( $active_id ) || !bbp_is_reply( $active_id ) ) { 
  14. $active_id = $topic_id; 
  15.  
  16. // Update only if published 
  17. if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) { 
  18. update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id ); 
  19.  
  20. return apply_filters( 'bbp_update_topic_last_active_id', (int) $active_id, $topic_id );