bbp_get_topic_id( $topic_id )

Return the topic id


Description Description


Parameters Parameters

$topic_id

(Optional) Used to check emptiness


Top ↑

Return Return

(int) The topic id


Top ↑

Source Source

File: includes/topics/template.php

	function bbp_get_topic_id( $topic_id = 0 ) {
		$bbp      = bbpress();
		$wp_query = bbp_get_wp_query();

		// Easy empty checking
		if ( ! empty( $topic_id ) && is_numeric( $topic_id ) ) {
			$bbp_topic_id = $topic_id;

		// Currently inside a topic loop
		} elseif ( ! empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
			$bbp_topic_id = $bbp->topic_query->post->ID;

		// Currently inside a search loop
		} elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
			$bbp_topic_id = $bbp->search_query->post->ID;

		// Currently viewing/editing a topic, likely alone
		} elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && ! empty( $bbp->current_topic_id ) ) {
			$bbp_topic_id = $bbp->current_topic_id;

		// Currently viewing/editing a topic, likely in a loop
		} elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) {
			$bbp_topic_id = $wp_query->post->ID;

		// Currently viewing/editing a reply
		} elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) {
			$bbp_topic_id = bbp_get_reply_topic_id();

		// Fallback
		} else {
			$bbp_topic_id = 0;
		}

		// Filter & return
		return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.