Hey all. I know this is a resolved topic, but I was able to snag code from this other topic to do this at a general (non-private groups) level.
Here’s their code (with a few simplifying edits from me):
/*
* Get the most recently replied-to topics, and their most recent reply
*/
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);
// default values
$post_types = array('reply');
$meta_key = '_bbp_last_reply_id';
// allow for topics with no replies
if ($include_empty_topics) {
$meta_key = '_bbp_last_active_id';
$post_types[] = 'topic';
}
// get the 5 topics with the most recent replies
$args = array(
'posts_per_page' => $show,
'post_type' => array('topic'),
'post_status' => array('publish'),
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => $meta_key,
);
// allow for specific forum limit
if ($forum){
$args['post_parent'] = $forum;
}
$query = new WP_Query($args);
$reply_ids = array();
// get the reply post->IDs for these most-recently-replied-to-topics
while($query->have_posts()){
$query->the_post();
if ($reply_post_id = get_post_meta(get_the_ID(), $meta_key, true)){
$reply_ids[] = $reply_post_id;
}
}
// get the actual replies themselves
$args = array(
'posts_per_page' => $show,
'post_type' => $post_types,
'post__in' => $reply_ids,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query($args);
ob_start();
// loop through results and output our rows
while($query->have_posts()){
$query->the_post();
// custom function for a single reply row
custom_bbpress_recent_reply_row_template( $query->current_post + 1 );
}
$output = ob_get_clean();
return $output;
}
add_shortcode('bbpress_recent_replies_by_topic', 'custom_bbpress_recent_replies_by_topic');
/*
* Executed during our custom loop
* - this should be the only thing you need to edit
*/
/*
* Executed during our custom loop
* - this should be the only thing you need to edit
*/
function custom_bbpress_recent_reply_row_template( $row_number ){
// get the reply title
$title = get_the_title();
// optional title adjustments -- delete or comment out to remove
// remove "Reply To: " from beginning of title
/* $title = str_replace('Reply To: ', '', $title); */
// trim title to specific number of characters (55 characters)
$title = substr( $title, 0, 55);
// trim title to specific number of words (5 words)...
/* $title = wp_trim_words( $title, 5, '...'); */
// determine if odd of even row
$row_class = ($row_number % 2) ? 'odd' : 'even';
?>
<div class="bbpress-recent-reply-row <?php print $row_class; ?>">
<div><a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print $title; ?></a>
<div>By: <?php the_author(); ?></div>
<div><?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></div>
<div><br></div>
</div>
<?php
// Refs
// https://codex.www.ads-software.com/Template_Tags#Post_tags
// https://codex.www.ads-software.com/Function_Reference/get_avatar
// https://codex.www.ads-software.com/Function_Reference/human_time_diff
// (template tags for bbpress)
// https://bbpress.trac.www.ads-software.com/browser/trunk/src/includes/users/template.php
// https://bbpress.trac.www.ads-software.com/browser/trunk/src/includes/replies/template.php
}
// allow shortcodes to run in widgets
add_filter( 'widget_text', 'do_shortcode');
// don't auto-wrap shortcode that appears on a line of it's own
add_filter( 'widget_text', 'shortcode_unautop');
To use it in a widget, you:
1. Cut and paste the code into your child theme’s function.php file
1. Create a new text widget
2. Paste in the shortcode [bbpress_recent_replies_by_topic include_empty_topics=1]