Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get topics of subscribed to forums?


  • athep
    Participant

    @athep

    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?

Viewing 21 replies - 1 through 21 (of 21 total)

  • Robin W
    Moderator

    @robin-w

    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; ?>

    athep
    Participant

    @athep

    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 possible


    Robin W
    Moderator

    @robin-w

    can you post the full error msg


    Robin W
    Moderator

    @robin-w

    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; ?>


    athep
    Participant

    @athep

    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?


    Robin W
    Moderator

    @robin-w

    can you post your corrected code


    athep
    Participant

    @athep

    <?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; ?>

    Robin W
    Moderator

    @robin-w

    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; ?>

    athep
    Participant

    @athep

    Same error indicating this line <?php if (in_array($forum_id, $subs)) { ?>


    Robin W
    Moderator

    @robin-w

    can I have the full error (you can take out site specific)


    Robin W
    Moderator

    @robin-w

    hold on you haven’t got the line

    <?php $subs = explode(',', $subs);


    Robin W
    Moderator

    @robin-w

    <?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; ?>

    athep
    Participant

    @athep

    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 21

    Line 21 is <?php if (in_array($forum_id, $subs)) { ?>


    Robin W
    Moderator

    @robin-w

    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?


    athep
    Participant

    @athep

    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


    athep
    Participant

    @athep

    @robin-w thank you for all the help, after a bit of tinkering I changed bbp_get_user_forum_subscriptions to bbp_get_user_topic_subscriptions and it worked flawlessly, thank you so much


    athep
    Participant

    @athep

    Correction, 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 closer


    Robin W
    Moderator

    @robin-w

    great – hope you get there


    athep
    Participant

    @athep

    @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 array

    I’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 ones


    athep
    Participant

    @athep

    I 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; ?>

    Robin W
    Moderator

    @robin-w

    no code that works is clumsy !!

Viewing 21 replies - 1 through 21 (of 21 total)
  • You must be logged in to reply to this topic.
Skip to toolbar