bbp_forum_query_last_reply_id

Returns the forum's last reply id.

Description

bbp_forum_query_last_reply_id( (int) $forum_id, (int) $topic_ids = 0 ); 

Parameters (2)

0. $forum_id (int)
The forum id.
1. $topic_ids — Optional. (int)
Topic ids

Usage

  1. if ( !function_exists( 'bbp_forum_query_last_reply_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // The forum id. 
  5. $forum_id = -1; 
  6.  
  7. // Optional. Topic ids 
  8. $topic_ids = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_forum_query_last_reply_id($forum_id, $topic_ids); 
  12.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { 
  2. global $wpdb; 
  3.  
  4. $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id'; 
  5. $reply_id = wp_cache_get( $cache_id, 'bbpress_posts' ); 
  6.  
  7. if ( false === $reply_id ) { 
  8.  
  9. if ( empty( $topic_ids ) ) { 
  10. $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 
  11.  
  12. if ( !empty( $topic_ids ) ) { 
  13. $topic_ids = implode( ', ', wp_parse_id_list( $topic_ids ) ); 
  14. $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 
  15. wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); // May be (int) 0 
  16. } else { 
  17. wp_cache_set( $cache_id, '0', 'bbpress_posts' ); 
  18.  
  19. return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );