Contents
bbp_get_topic_id( $topic_id )
Return the topic id
Description
Parameters
- $topic_id
-
(Optional) Used to check emptiness
Return
(int) The topic id
Source
File: bp-forums/topics/template.php
function bbp_get_topic_id( $topic_id = 0 ) { global $wp_query; $bbp = bbpress(); // 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; } return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id ); }
Changelog
Version | Description |
---|---|
bbPress (r2485) | Introduced. |
Related
Uses
Uses | Description |
---|---|
bp-forums/classes/class-bbpress.php: bbpress() |
The main function responsible for returning the one true bbPress Instance to functions everywhere. |
bp-forums/common/template.php: bbp_is_single_reply() |
Viewing a single reply |
bp-forums/common/template.php: bbp_is_reply_edit() |
Check if current page is a reply edit page |
bp-forums/common/template.php: bbp_is_topic() |
Check if current page is a Forums topic |
bp-forums/common/template.php: bbp_is_single_topic() |
Viewing a single topic |
bp-forums/common/template.php: bbp_is_topic_edit() |
Check if current page is a topic edit page |
bp-forums/replies/template.php: bbp_get_reply_topic_id() |
Return the topic id a reply belongs to |
Used By | Description |
---|---|
bp-forums/classes/class-bp-rest-topics-endpoint.php: BP_REST_Topics_Endpoint::get_topic_current_user_permissions() |
Topic permissions for the current user. |
bp-forums/classes/class-bp-rest-topics-endpoint.php: BP_REST_Topics_Endpoint::get_topic_revisions() |
Get revisions for topic. |
bp-forums/classes/class-bp-rest-forums-endpoint.php: BP_REST_Forums_Endpoint::bbp_rest_get_topic_last_active_time() |
Last active time for Topic. |
bp-forums/templates/default/bbpress-functions.php: BBP_Default::media_localize_script() |
Localize scripts for Media component for forums |
bp-forums/core/theme-compat.php: bbp_template_include_theme_compat() |
Reset main query vars and filter ‘the_content’ to output a Forums template part as needed. |
bp-forums/templates/default/bbpress-functions.php: BBP_Default::localize_topic_script() |
Load localizations for topic script |
bp-forums/topics/template.php: bbp_get_form_topic_status_dropdown() |
Returns topic status downdown |
bp-forums/topics/template.php: bbp_topic_notices() |
Displays topic notices |
bp-forums/topics/template.php: bbp_get_form_topic_type_dropdown() |
Returns topic type select box (normal/sticky/super sticky) |
bp-forums/topics/template.php: bbp_get_topic_reply_link() |
Return the link to go directly to the reply form |
bp-forums/topics/template.php: bbp_get_topic_trash_link() |
Return the trash link of the topic |
bp-forums/topics/template.php: bbp_get_topic_close_link() |
Return the close link of the topic |
bp-forums/topics/template.php: bbp_get_topic_stick_link() |
Return the stick link of the topic |
bp-forums/topics/template.php: bbp_get_topic_merge_link() |
Return the merge link of the topic |
bp-forums/topics/template.php: bbp_get_topic_spam_link() |
Return the spam link of the topic |
bp-forums/topics/template.php: bbp_get_topic_edit_link() |
Return the edit link of the topic |
bp-forums/topics/template.php: bbp_get_topic_edit_url() |
Return URL to the topic edit page |
bp-forums/topics/template.php: bbp_get_topic_tag_list() |
Return the tags of a topic |
bp-forums/topics/template.php: bbp_get_topic_class() |
Return the row class of a topic |
bp-forums/topics/template.php: bbp_get_topic_admin_links() |
Return admin links for topic. |
bp-forums/topics/template.php: bbp_get_topic_replies_link() |
Return the replies link of the topic |
bp-forums/topics/template.php: bbp_get_topic_reply_count() |
Return total reply count of a topic |
bp-forums/topics/template.php: bbp_get_topic_post_count() |
Return total post count of a topic |
bp-forums/topics/template.php: bbp_get_topic_reply_count_hidden() |
Return total hidden reply count of a topic (hidden includes trashed and spammed replies) |
bp-forums/topics/template.php: bbp_get_topic_voice_count() |
Return total voice count of a topic |
bp-forums/topics/template.php: bbp_get_topic_last_reply_url() |
Return the link to the last reply in a topic |
bp-forums/topics/template.php: bbp_get_topic_freshness_link() |
Returns link to the most recent activity inside a topic, complete with link attributes and content. |
bp-forums/topics/template.php: bbp_get_topic_last_reply_id() |
Return the topics last update date/time (aka freshness) |
bp-forums/topics/template.php: bbp_get_topic_last_reply_title() |
Return the title of the last reply inside a topic |
bp-forums/topics/template.php: bbp_get_topic_last_reply_permalink() |
Return the link to the last reply in a topic |
bp-forums/topics/template.php: bbp_get_topic_forum_id() |
Return the forum id a topic belongs to |
bp-forums/topics/template.php: bbp_get_topic_last_active_id() |
Return the topics last active ID |
bp-forums/topics/template.php: bbp_get_topic_last_active_time() |
Return the topics last update date/time (aka freshness) |
bp-forums/topics/template.php: bbp_get_topic_forum_title() |
Return the title of the forum a topic belongs to |
bp-forums/topics/template.php: bbp_get_topic_author_link() |
Return the author link of the topic |
bp-forums/topics/template.php: bbp_get_topic_author_url() |
Return the author url of the topic |
bp-forums/topics/template.php: bbp_get_topic_author_email() |
Return the topic author email address |
bp-forums/topics/template.php: bbp_get_topic_author_role() |
Return the topic author role |
bp-forums/topics/template.php: bbp_is_topic_trash() |
Is the topic trashed? |
bp-forums/topics/template.php: bbp_is_topic_anonymous() |
Is the posted by an anonymous user? |
bp-forums/topics/template.php: bbp_get_topic_author() |
Deprecated. Use bbp_get_topic_author_display_name() instead. |
bp-forums/topics/template.php: bbp_get_topic_author_id() |
Return the author ID of the topic |
bp-forums/topics/template.php: bbp_get_topic_author_display_name() |
Return the author display_name of the topic |
bp-forums/topics/template.php: bbp_get_topic_author_avatar() |
Return the author avatar of the topic |
bp-forums/topics/template.php: bbp_is_topic_spam() |
Is the topic marked as spam? |
bp-forums/topics/template.php: bbp_get_topic_revisions() |
Return the revisions of the topic |
bp-forums/topics/template.php: bbp_get_topic_status() |
Return the status of the topic |
bp-forums/topics/template.php: bbp_is_topic_sticky() |
Is the topic a sticky or super sticky? |
bp-forums/topics/template.php: bbp_is_topic_super_sticky() |
Is the topic a super sticky? |
bp-forums/topics/template.php: bbp_is_topic_published() |
Is the topic not spam or deleted? |
bp-forums/topics/template.php: bbp_get_topic_excerpt() |
Return the excerpt of the topic |
bp-forums/topics/template.php: bbp_get_topic_post_date() |
Return the post date and time of a topic |
bp-forums/topics/template.php: bbp_get_topic_pagination() |
Returns pagination links of a topic within the topic loop |
bp-forums/topics/template.php: bbp_topic_content_append_revisions() |
Append revisions to the topic content |
bp-forums/topics/template.php: bbp_get_topic_revision_log() |
Return the formatted revision log of the topic |
bp-forums/topics/template.php: bbp_get_topic_raw_revision_log() |
Return the raw revision log of the topic |
bp-forums/topics/template.php: bbp_get_topic() |
Gets a topic |
bp-forums/topics/template.php: bbp_get_topic_permalink() |
Return the link to the topic |
bp-forums/topics/template.php: bbp_get_topic_title() |
Return the title of the topic |
bp-forums/topics/template.php: bbp_get_topic_content() |
Return the content of the topic |
bp-forums/topics/template.php: bbp_topic_id() |
Output the topic id |
bp-forums/topics/functions.php: bbp_trashed_topic() |
Called after trashing a topic |
bp-forums/topics/functions.php: bbp_untrashed_topic() |
Called after untrashing a topic |
bp-forums/topics/functions.php: bbp_get_topic_tag_names() |
Get topic tags for a specific topic ID |
bp-forums/topics/functions.php: bbp_display_topics_feed_rss2() |
Output an RSS2 feed of topics, based on the query passed. |
bp-forums/topics/functions.php: bbp_check_topic_edit() |
Redirect if unathorized user is attempting to edit a topic |
bp-forums/topics/functions.php: bbp_stick_topic() |
Sticks a topic to a forum or front |
bp-forums/topics/functions.php: bbp_unstick_topic() |
Unsticks a topic both from front and it’s forum |
bp-forums/topics/functions.php: bbp_delete_topic() |
Called before deleting a topic. |
bp-forums/topics/functions.php: bbp_trash_topic() |
Called before trashing a topic |
bp-forums/topics/functions.php: bbp_untrash_topic() |
Called before untrashing a topic |
bp-forums/topics/functions.php: bbp_deleted_topic() |
Called after deleting a topic |
bp-forums/topics/functions.php: bbp_update_topic_forum_id() |
Update the topic’s forum id |
bp-forums/topics/functions.php: bbp_update_topic_topic_id() |
Update the topic’s topic id |
bp-forums/topics/functions.php: bbp_update_topic_reply_count() |
Adjust the total reply count of a topic |
bp-forums/topics/functions.php: bbp_update_topic_reply_count_hidden() |
Adjust the total hidden reply count of a topic (hidden includes trashed and spammed replies) |
bp-forums/topics/functions.php: bbp_update_topic_last_active_id() |
Update the topic with the last active post ID |
bp-forums/topics/functions.php: bbp_update_topic_last_active_time() |
Update the topics last active date/time (aka freshness) |
bp-forums/topics/functions.php: bbp_update_topic_last_reply_id() |
Update the topic with the most recent reply ID |
bp-forums/topics/functions.php: bbp_update_topic_voice_count() |
Adjust the total voice count of a topic |
bp-forums/topics/functions.php: bbp_update_topic_anonymous_reply_count() |
Adjust the total anonymous reply count of a topic |
bp-forums/topics/functions.php: bbp_update_topic_revision_log() |
Update the revision log of the topic |
bp-forums/topics/functions.php: bbp_remove_topic_from_all_favorites() |
Remove a deleted topic from all users’ favorites |
bp-forums/topics/functions.php: bbp_remove_topic_from_all_subscriptions() |
Remove a deleted topic from all users’ subscriptions |
bp-forums/topics/functions.php: bbp_bump_topic_reply_count() |
Bump the total reply count of a topic |
bp-forums/topics/functions.php: bbp_bump_topic_reply_count_hidden() |
Bump the total hidden reply count of a topic |
bp-forums/topics/functions.php: bbp_update_topic() |
Handle all the extra meta stuff from posting a new topic |
bp-forums/topics/functions.php: bbp_update_topic_walker() |
Walks up the post_parent tree from the current topic_id, and updates the counts of forums above it. This calls a few internal functions that all run manual queries against the database to get their results. As such, this function can be costly to run but is necessary to keep everything accurate. |
bp-forums/topics/functions.php: bbp_move_topic_handler() |
Handle the moving of a topic from one forum to another. This includes walking up the old and new branches and updating the counts. |
bp-forums/users/template.php: bbp_current_user_can_access_create_topic_form() |
Performs a series of checks to ensure the current user can create topics. |
bp-forums/users/template.php: bbp_get_user_subscribe_link() |
Return the link to subscribe/unsubscribe from a forum or topic |
bp-forums/users/template.php: bbp_get_user_favorites_link() |
User favorites link |
bp-forums/users/functions.php: bbp_is_user_subscribed_to_topic() |
Check if a topic is in user’s subscription list or not |
bp-forums/users/functions.php: bbp_get_topic_subscribers() |
Get the users who have subscribed to the topic |
bp-forums/users/functions.php: bbp_is_user_favorite() |
Check if a topic is in user’s favorites or not |
bp-forums/users/functions.php: bbp_get_topic_favoriters() |
Get the users who have made the topic favorite |
bp-forums/groups.php: BBP_Forums_Group_Extension::replies_pagination() |
Fix pagination of replies on topic view |
bp-forums/forums/functions.php: bbp_update_forum_topic_count_hidden() |
Adjust the total hidden topic count of a forum (hidden includes trashed and spammed topics) |
bp-forums/common/widgets.php: BBP_Topics_Widget::widget() |
Displays the output, the topic list |
bp-forums/common/template.php: bbp_topic_form_fields() |
Output the required hidden fields when creating/editing a topic |
bp-forums/common/template.php: bbp_reply_form_fields() |
Output the required hidden fields when creating/editing a reply |
bp-forums/common/template.php: bbp_merge_topic_form_fields() |
Merge topic form fields |
bp-forums/common/template.php: bbp_split_topic_form_fields() |
Split topic form fields |
bp-forums/common/functions.php: bbp_notify_topic_subscribers() |
Sends notification emails for new replies to subscribed topics |
bp-forums/common/functions.php: bbp_notify_forum_subscribers() |
Sends notification emails for new topics to subscribed forums |
bp-forums/activity.php: BBP_BuddyPress_Activity::topic_update() |
Update the activity stream entry when a topic status changes |
bp-forums/activity.php: BBP_BuddyPress_Activity::reply_create() |
Record an activity stream entry when a reply is created |
bp-forums/activity.php: BBP_BuddyPress_Activity::topic_create() |
Record an activity stream entry when a topic is created or updated |
bp-forums/extend/akismet.php: BBP_Akismet::filter_post_terms() |
Handle any terms submitted with a post flagged as spam |
bp-forums/replies/template.php: bbp_get_reply_to_link() |
Return the link for a reply to a reply |
bp-forums/replies/template.php: bbp_get_reply_position() |
Return the numeric position of a reply within a topic |
bp-forums/replies/template.php: bbp_get_reply_topic_id() |
Return the topic id a reply belongs to |
bp-forums/replies/template.php: bbp_has_replies() |
The main reply loop. WordPress makes this easy for us |
bp-forums/replies/functions.php: _bbp_has_replies_where() |
Used by bbp_has_replies() to add the lead topic post to the posts loop |
bp-forums/replies/functions.php: bbp_get_reply_position_raw() |
Get the position of a reply by querying the DB directly for the replies of a given topic. |
bp-forums/replies/functions.php: bbp_update_reply() |
Handle all the extra meta stuff from posting a new reply or editing a reply |
bp-forums/replies/functions.php: bbp_update_reply_topic_id() |
Update the reply with its topic id it is in |
bp-forums/search/template.php: bbp_the_search_result() |
Loads up the current search result in the loop |
bp-core/deprecated/buddyboss/1.0.php: bbp_get_single_topic_description() |
Return a fancy description of the current topic, including total topics, total replies, and last activity. |
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.