bb_cache_last_posts

The BuddyPress bb cache last posts function.

Description

bb_cache_last_posts( (constant) $_topics = false, (bool) $author_cache = true ); 

Parameters (2)

0. $topics (constant)
The topics.
1. $author_cache — Optional. (bool) => true
The author cache.

Usage

  1. if ( !function_exists( 'bb_cache_last_posts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-posts.php'; 
  3.  
  4. // The topics. 
  5. $topics = null; 
  6.  
  7. // The author cache. 
  8. $author_cache = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_cache_last_posts($topics, $author_cache); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-posts.php  
  1. function bb_cache_last_posts( $_topics = false, $author_cache = true ) { 
  2. global $topics, $bbdb; 
  3. if ( !$_topics ) 
  4. $_topics =& $topics; 
  5. if ( !is_array($_topics) ) 
  6. return false; 
  7.  
  8. $last_post_ids = array(); 
  9. $topic_ids = array(); 
  10. foreach ( $_topics as $topic ) 
  11. if ( is_object($topic) ) 
  12. $last_post_ids[] = (int) $topic->topic_last_post_id; 
  13. else if ( is_numeric($topic) && false !== $cached_topic = wp_cache_get( $topic, 'bb_topic' ) ) 
  14. $last_post_ids[] = (int) $cached_topic->topic_last_post_id; 
  15. else if ( is_numeric($topic) ) 
  16. $topic_ids[] = (int) $topic; 
  17.  
  18. if ( !empty($last_post_ids) ) { 
  19. $_last_post_ids = join(', ', $last_post_ids); 
  20. $posts = (array) bb_cache_posts( "SELECT post_id FROM $bbdb->posts WHERE post_id IN ($_last_post_ids) AND post_status = 0", true ); 
  21. if ( $author_cache ) 
  22. bb_post_author_cache( $posts ); 
  23.  
  24. if ( !empty($topic_ids) ) {  
  25. $_topic_ids = join(', ', $topic_ids); 
  26. $posts = (array) bb_cache_posts( "SELECT p.post_id FROM $bbdb->topics AS t LEFT JOIN $bbdb->posts AS p ON ( t.topic_last_post_id = p.post_id ) WHERE t.topic_id IN ($_topic_ids) AND p.post_status = 0", true ); 
  27. if ( $author_cache ) 
  28. bb_post_author_cache( $posts );