bb_get_first_post

The BuddyPress bb get first post function.

Description

bb_get_first_post( (constant) $_topic = false, (bool) $author_cache = true ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'bb_get_first_post' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-posts.php'; 
  3.  
  4. // The topic. 
  5. $topic = null; 
  6.  
  7. // The author cache. 
  8. $author_cache = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_get_first_post($topic, $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_get_first_post( $_topic = false, $author_cache = true ) { 
  2. global $topic, $bb_first_post_cache, $bb_post; 
  3. if ( !$_topic ) 
  4. $topic_id = (int) $topic->topic_id; 
  5. else if ( is_object($_topic) ) 
  6. $topic_id = (int) $_topic->topic_id; 
  7. else if ( is_numeric($_topic) ) 
  8. $topic_id = (int) $_topic; 
  9.  
  10. if ( !$topic_id ) 
  11. return false; 
  12.  
  13. if ( isset($bb_first_post_cache[$topic_id]) ) { 
  14. $post = bb_get_post( $bb_first_post_cache[$topic_id] ); 
  15. } else { 
  16. $first_posts = bb_cache_first_posts( array($topic_id), $author_cache ); 
  17. if ( isset($first_posts[$topic_id]) ) 
  18. $post = $first_posts[$topic_id]; 
  19.  
  20. if ( $post ) { 
  21. $bb_post = $post; 
  22. return $bb_post; 
  23.  
  24. return false;