get_topic

Topics.

Description

get_topic( $id, (bool) $cache = true ); 

Parameters (2)

0. $id
The id.
1. $cache — Optional. (bool) => true
The cache.

Usage

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

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-topics.php  
  1. function get_topic( $id, $cache = true ) { 
  2. global $bbdb; 
  3.  
  4. if ( !is_numeric($id) ) { 
  5. list($slug, $sql) = bb_get_sql_from_slug( 'topic', $id ); 
  6. $id = wp_cache_get( $slug, 'bb_topic_slug' ); 
  7.  
  8. // not else 
  9. if ( is_numeric($id) ) { 
  10. $id = (int) $id; 
  11. $sql = "topic_id = $id"; 
  12.  
  13. if ( 0 === $id || !$sql ) 
  14. return false; 
  15.  
  16. // &= not =& 
  17. $cache &= 'AND topic_status = 0' == $where = apply_filters( 'get_topic_where', 'AND topic_status = 0' ); 
  18.  
  19. if ( ( $cache || !$where ) && is_numeric($id) && false !== $topic = wp_cache_get( $id, 'bb_topic' ) ) 
  20. return $topic; 
  21.  
  22. // $where is NOT bbdb:prepared 
  23. $topic = $bbdb->get_row( "SELECT * FROM $bbdb->topics WHERE $sql $where" ); 
  24. $topic = bb_append_meta( $topic, 'topic' ); 
  25.  
  26. if ( $cache ) { 
  27. wp_cache_set( $topic->topic_id, $topic, 'bb_topic' ); 
  28. wp_cache_add( $topic->topic_slug, $topic->topic_id, 'bb_topic_slug' ); 
  29.  
  30. return $topic;