bbp_get_topic

Gets a topic.

Description

bbp_get_topic( (int|object) $topic, (constant) $output = OBJECT, (string) $filter = 'raw' ); 

Parameters (3)

0. $topic (int|object)
Topic id or topic object
1. $output — Optional. (constant) => OBJECT
OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
2. $filter — Optional. (string) => 'raw'
The filter.

Options

    ;        


    Usage

    1. if ( !function_exists( 'bbp_get_topic' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/template.php'; 
    3.  
    4. // Topic id or topic object 
    5. $topic = null; 
    6.  
    7. // Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT 
    8. $output = OBJECT; 
    9.  
    10. // The filter. 
    11. $filter = 'raw'; 
    12.  
    13. // NOTICE! Understand what this does before running. 
    14. $result = bbp_get_topic($topic, $output, $filter); 
    15.  

    Defined (1)

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

    /includes/topics/template.php  
    1. function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) { 
    2.  
    3. // Use topic ID 
    4. if ( empty( $topic ) || is_numeric( $topic ) ) 
    5. $topic = bbp_get_topic_id( $topic ); 
    6.  
    7. // Attempt to load the topic 
    8. $topic = get_post( $topic, OBJECT, $filter ); 
    9. if ( empty( $topic ) ) 
    10. return $topic; 
    11.  
    12. // Bail if post_type is not a topic 
    13. if ( $topic->post_type !== bbp_get_topic_post_type() ) 
    14. return null; 
    15.  
    16. // Tweak the data type to return 
    17. if ( $output === OBJECT ) { 
    18. return $topic; 
    19.  
    20. } elseif ( $output === ARRAY_A ) { 
    21. $_topic = get_object_vars( $topic ); 
    22. return $_topic; 
    23.  
    24. } elseif ( $output === ARRAY_N ) { 
    25. $_topic = array_values( get_object_vars( $topic ) ); 
    26. return $_topic; 
    27.  
    28.  
    29. return apply_filters( 'bbp_get_topic', $topic, $output, $filter );