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

Gets a forum

Description

Parameters

$forum

(int|object) (Required) forum id or forum object

$output

(string) (Optional) OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT

Default value: OBJECT

$filter

(string) (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

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

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.