bbp_get_forum( int|object $forum, string $output = OBJECT, string $filter = 'raw' )
Gets a forum
Description
Parameters
- $forum
-
(Required) forum id or forum object
- $output
-
(Optional) OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
Default value: OBJECT
- $filter
-
(Optional) Sanitation filter. See sanitize_post()
Default value: 'raw'
Return
(mixed) Null if error or forum (in specified form) if success
Source
File: bp-forums/forums/template.php
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | function bbp_get_forum( $forum , $output = OBJECT, $filter = 'raw' ) { // Use forum ID if ( empty ( $forum ) || is_numeric ( $forum ) ) $forum = bbp_get_forum_id( $forum ); // Attempt to load the forum $forum = get_post( $forum , OBJECT, $filter ); if ( empty ( $forum ) ) return $forum ; // Bail if post_type is not a forum if ( $forum ->post_type !== bbp_get_forum_post_type() ) return null; // Tweak the data type to return if ( $output === OBJECT ) { return $forum ; } elseif ( $output === ARRAY_A ) { $_forum = get_object_vars( $forum ); return $_forum ; } elseif ( $output === ARRAY_N ) { $_forum = array_values ( get_object_vars( $forum ) ); return $_forum ; } return apply_filters( 'bbp_get_forum' , $forum , $output , $filter ); } |
Changelog
Version | Description |
---|---|
bbPress (r2787) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.