Get topics of subscribed to forums?
-
Hello everyone,
I have this loop in my custom theme that lists the forums a user is subscribed to
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <p><?php bbp_forum_title(); ?></p> <?php endwhile; ?> <?php endif; ?>I’m not sure if it is the most efficient technique but it is working fine.
Now I’m trying to retrieve the topics under those forums, if I’m subscribed to forum a and not b, how can I retrieve all the topics of only forum a?
-
untested but something like
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php $subs = bbp_get_user_forum_subscriptions( $uid ) ; ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <?php $forum_id = bbp_get_forum_id( $forum_id ); ?> <?php if (in_array($forum_id, $subs)) { ?> <p><?php bbp_forum_title(); ?></p> etc. <php } ?> <?php endwhile; ?> <?php endif; ?>Hello Robin, thank you for your reply. I got this error
Warning: in_array() expects parameter 2 to be array, bool given in...I’d appreciate helping me figure it out if possiblecan you post the full error msg
although this might fix that
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?>
<?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?>
<?php $subs = bbp_get_user_forum_subscriptions( $uid ) ; ?>
<?php $subs = explode(‘,’, $subs);
<?php while ( bbp_forums() ) : bbp_the_forum(); ?>
<?php $forum_id = bbp_get_forum_id( $forum_id ); ?>
<?php if (in_array($forum_id, $subs)) { ?>
<p><?php bbp_forum_title(); ?></p>
etc.
<php } ?>
<?php endwhile; ?>
<?php endif; ?>There were a few syntax errors I fixed with your code, and the error message ends with the files location stating that the error comes from the line ‘<?php if (in_array($forum_id, $subs)) { ?>’
Your second snippet returns null, nothing, maybe bbp_forum_title() won’t work in this context?
can you post your corrected code
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php $subs = bbp_get_user_forum_subscriptions( $uid ) ; ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <?php $forum_id = bbp_get_forum_id( $forum_id ); ?> <?php if (in_array($forum_id, $subs)) { ?> <p><?php bbp_forum_title(); ?></p> <?php } ?> <?php endwhile; ?> <?php endif; ?>try
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php $subs = bbp_get_user_forum_subscriptions( $uid ) ; ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <?php $forum_id = $bbp->forum_query->post->ID; ?> <?php if (in_array($forum_id, $subs)) { ?> <p><?php bbp_forum_title(); ?></p> <?php } ?> <?php endwhile; ?> <?php endif; ?>Same error indicating this line
<?php if (in_array($forum_id, $subs)) { ?>can I have the full error (you can take out site specific)
hold on you haven’t got the line
<?php $subs = explode(',', $subs);<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php $subs = bbp_get_user_forum_subscriptions( $uid ) ; ?> <?php $subs = explode(',', $subs); <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <?php $forum_id = $bbp->forum_query->post->ID; ?> <?php if (in_array($forum_id, $subs)) { ?> <p><?php bbp_forum_title(); ?></p> <?php } ?> <?php endwhile; ?> <?php endif; ?>I have included
$subs = explode(',' , $subs);and it’s returning nothing, it has no error or any output..The other error was
Warning: in_array() expects parameter 2 to be array, bool given in ..../content-main.php on line 21Line 21 is
<?php if (in_array($forum_id, $subs)) { ?>The
$subs = explode(',' , $subs);turns the string in the database to an array.Can you confirm for the user selected that they have active subs?
It’s still returning null, no output whatsoever. I even
print_r($subs)inside the while loop and nothing shows up, I’m using the latest versions of bbpress and wordpress, the theme is a blank starter theme with only bbpress plugin activated@robin-w thank you for all the help, after a bit of tinkering I changed
bbp_get_user_forum_subscriptionstobbp_get_user_topic_subscriptionsand it worked flawlessly, thank you so muchCorrection, I am getting the bbp_forum_title() that we passed but not
<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>that I was initially trying to filter.. No worries tho, one step closergreat – hope you get there
@robin-w I visited your website and noticed all the amazing work you’ve done, thank you.
What I’ve been trying to do all along was to get your shortcode
[bbp-display-topic-index show='5' forum ='10,11,12']to php so that the forums could be the IDs of the forums the user is subscribed to.. so an arrayI’ve been trying to get it to work to no avail,
[bbp-display-topic-index show='5' forum ='$forum_id']or the likes return nill or with all the topics from all the forums, not just the subscribed onesI finally got it to work clumsily
<?php global $current_user; get_currentuserinfo(); $uid = bbp_get_current_user_id(); ?> <?php if ( bbp_get_user_forum_subscriptions( $uid ) ) : ?> <?php while ( bbp_forums() ) : bbp_the_forum(); ?> <?php $subs[] = bbp_get_forum_id(); ?> <?php endwhile; ?> <?php $forumid = implode(', ', $subs); ?> <?php echo do_shortcode('[bbp-display-topic-index template ="short" forum="' . $forumid . '"]'); ?> <?php endif; ?>no code that works is clumsy !!
- You must be logged in to reply to this topic.