bb_cache_first_posts

The BuddyPress bb cache first posts function.

Description

bb_cache_first_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_first_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_first_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_first_posts( $_topics = false, $author_cache = true ) { 
  2. global $topics, $bb_first_post_cache, $bbdb; 
  3. if ( !$_topics ) 
  4. $_topics =& $topics; 
  5. if ( !is_array($_topics) ) 
  6. return false; 
  7.  
  8. $topic_ids = array(); 
  9. foreach ( $_topics as $topic ) 
  10. if ( is_object($topic) ) 
  11. $topic_ids[] = (int) $topic->topic_id; 
  12. else if ( is_numeric($topic) ) 
  13. $topic_ids[] = (int) $topic; 
  14.  
  15. $_topic_ids = join(', ', $topic_ids); 
  16.  
  17. $posts = (array) bb_cache_posts( "SELECT post_id FROM $bbdb->posts WHERE topic_id IN ($_topic_ids) AND post_position = 1", true ); 
  18.  
  19. $first_posts = array(); 
  20. foreach ( $posts as $post ) { 
  21. $bb_first_post_cache[(int) $post->topic_id] = (int) $post->post_id; 
  22. $first_posts[(int) $post->topic_id] = $post; 
  23.  
  24. if ( $author_cache ) 
  25. bb_post_author_cache( $posts ); 
  26.  
  27. return $first_posts;