bbp_get_forum_id

Return the forum id.

Description

(int) bbp_get_forum_id( (int) $forum_id = 0 ); 

Returns (int)

The forum id

Parameters (1)

0. $forum_id — Optional. (int)
Used to check emptiness

Usage

  1. if ( !function_exists( 'bbp_get_forum_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/template.php'; 
  3.  
  4. // Optional. Used to check emptiness 
  5. $forum_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_forum_id($forum_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/forums/template.php  
  1. function bbp_get_forum_id( $forum_id = 0 ) { 
  2. global $wp_query; 
  3.  
  4. $bbp =bbpress); 
  5.  
  6. // Easy empty checking 
  7. if ( !empty( $forum_id ) && is_numeric( $forum_id ) ) { 
  8. $bbp_forum_id = $forum_id; 
  9.  
  10. // Currently inside a forum loop 
  11. } elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) { 
  12. $bbp_forum_id = $bbp->forum_query->post->ID; 
  13.  
  14. // Currently inside a search loop 
  15. } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) { 
  16. $bbp_forum_id = $bbp->search_query->post->ID; 
  17.  
  18. // Currently viewing a forum 
  19. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && !empty( $bbp->current_forum_id ) ) { 
  20. $bbp_forum_id = $bbp->current_forum_id; 
  21.  
  22. // Currently viewing a forum 
  23. } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) { 
  24. $bbp_forum_id = $wp_query->post->ID; 
  25.  
  26. // Currently viewing a topic 
  27. } elseif ( bbp_is_single_topic() ) { 
  28. $bbp_forum_id = bbp_get_topic_forum_id(); 
  29.  
  30. // Fallback 
  31. } else { 
  32. $bbp_forum_id = 0; 
  33.  
  34. return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );