bbp_update_topic_last_reply_id

Update the topic with the most recent reply ID.

Description

(int) bbp_update_topic_last_reply_id( (int) $topic_id = 0, (int) $reply_id = 0 ); 

Returns (int)

Reply id

Parameters (2)

0. $topic_id — Optional. (int)
Topic id to update
1. $reply_id — Optional. (int)
Reply id

Usage

  1. if ( !function_exists( 'bbp_update_topic_last_reply_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. Reply id 
  8. $reply_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_topic_last_reply_id($topic_id, $reply_id); 
  12.  

Defined (1)

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

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