How do I find the bbpress forum ID for a forum in a buddypress group?

I am trying to modify this code https://www.daggerhart.com/bbpress-recent-replies-shortcode/ but I have specific questions and cannot find the answer. This code above generates a shortcode like [bbpress_recent_replies_by_topic show=10 forum=123]

I have a buddypress site with groups, and each group has its own bbpress forum. I want to list the recent replies for the forum assigned to that group (only) when a user visits the group page. So basically I want to assign the forum ID based on whichever group the user is in and is seeing the widget in.

This is the function in the code above:

function custom_bbpress_recent_replies_by_topic($atts){
    $short_array = shortcode_atts(array('show' = 5, 'forum' = false, 'include_empty_topics' = false), $atts);
    extract($short_array);

Instead of 'forum' = false, I want it to point to 'forum' = _bbp_forum_id or something like that. However, that doesn't work because I'm at the group home page so there is no forum there yet until you click "forums" in the group menu. I don't know how database links the budddypress group to the bbpress forum id.

Some questions: 1) How do I find out the forum id for the group’s assigned forum? Is it _bbp_forum_id ? 2) How do I then assign that forum ID to to be the default forum ID for the widget in the code above?

Topic bbpress buddypress Wordpress

Category Web


The forum id for a group is stored in the {yourprefix}_bp_groups_groupsmeta table where group_id is the group id and the key is forum_id and the value is a serialized array.

Instead of a shortcode, it may be easier to add a function call in a bp groups template. Something like: echo gauray_recent_replies( bp_get_group_id() );

function gauray_recent_replies( $group_id ) {
   $forum_id = bbp_get_group_forum_ids( $group_id );
   // collect and return replies
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.