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

Gets a topic

Description

Parameters

$topic

(int|object) (Required) Topic id or topic 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 topic (in specified form) if success

Source

File: bp-forums/topics/template.php

function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {

	// Use topic ID
	if ( empty( $topic ) || is_numeric( $topic ) )
		$topic = bbp_get_topic_id( $topic );

	// Attempt to load the topic
	$topic = get_post( $topic, OBJECT, $filter );
	if ( empty( $topic ) )
		return $topic;

	// Bail if post_type is not a topic
	if ( $topic->post_type !== bbp_get_topic_post_type() )
		return null;

	// Tweak the data type to return
	if ( $output === OBJECT ) {
		return $topic;

	} elseif ( $output === ARRAY_A ) {
		$_topic = get_object_vars( $topic );
		return $_topic;

	} elseif ( $output === ARRAY_N ) {
		$_topic = array_values( get_object_vars( $topic ) );
		return $_topic;

	}

	return apply_filters( 'bbp_get_topic', $topic, $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.