bbp_get_forum

Gets a forum.

Description

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

Parameters (3)

0. $forum (int|object)
Forum id or forum 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_forum' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/template.php'; 
    3.  
    4. // forum id or forum object 
    5. $forum = 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_forum($forum, $output, $filter); 
    15.  

    Defined (1)

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

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