Out of the box, bbpress shows topics from a particular forum when you are on that forum’s archive page. Makes sense. If that forum has a sub-forum, it will link to those sub-forums, but it won’t show the actual topics from that sub-forum.
I’m trying to modify the default bbpress loop on a forum page (loop-topics.php) to include the sub-forum topics.
Here’s an explanation:
Forum A
Sub-forum A1
Sub-forum A2
Forum B
Sub-forum B1
Sub-forum B2
So when viewing Forum A’s archive page, I’d like to show topics from Forum A, sub-forum A1 and sub-forum A2.
The code needs to be dynamic in order to work with whatever parent forum archive a user is on.
You can pass wp_query args into bb_has_topics(), but I can only only come up with code that shows topics from one forum – not multiple forums.
To better explain what I’m working with, here’s an example of a loop that grabs topics from the parent forum:
<?php
$parents = get_post_ancestors( $post->ID );
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
$parent = get_page( $id );
?>
<?php $bbp_loop_args = array('post_parent' => $parent->ID, 'post_type' => 'topic'); ?>
<?php if ( bbp_has_topics($bbp_loop_args) ) : ?>
<?php while ( bbp_topics() ) : bbp_the_topic(); ?>
<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
<?php endwhile; ?>
<?php endif;?>
Any ideas on how this can be achieved?