Skip to:
Content
Pages
Categories
Search
Top
Bottom

User Activity – Topics Started or Replied To


  • FiveOneDigital
    Participant

    @fiveonedigital

    Hey,

    I may just be missing something, but is there any way to get all of the topics a user interacted with?

    I know “if ( bbp_get_user_topics_started() ) :” gets the posts the user created, but is there something similar for replied to?

    I’d ideally want two different pages (My Posts & My Replies) but I’d be fine if I can only get all the topics a user was active in (started or joined).

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I`m not sure how familiar you are with WordPress and PHP, I consider myself a novice in PHP but well-versed in WordPress. It might be a bit technical and it might be the wrong way to do things, but here is how I quickly put it together.

    Open functions.php in your theme.
    Add the following function to the file (within the PHP tags):

    function bbp_get_user_replies( $user_id = 0 ) {
    
    // Validate user
    $user_id = bbp_get_user_id( $user_id );
    if ( empty( $user_id ) )
        return false;
    
    // Query defaults
    $default_query = array(
        'author'         => $user_id,
        'show_stickies'  => false,
        'order'          => 'DESC',
    );
    
    // Try to get the topics
    $query = bbp_has_replies( $default_query );
    if ( empty( $query ) )
        return false;
    
    return apply_filters( 'bbp_get_user_replies', $query, $user_id );
    }
    

    Then to list the replies just add to whatever page you want to list them:

    As you can see this is basically the same code as the bbp_get_user_topics_started function, just modified to get the replies instead.

    If anyone have a better solution I`d love to hear it.

    Sorry, somehow the code did not output even if it looked like it would in the preview. Trying again:

    Then to list the replies just add to whatever page you want to list them:

    if ( bbp_get_user_replies() ) : 
       bbp_get_template_part( 'pagination', 'replies' ); 
       bbp_get_template_part( 'loop',       'replies' ); 
       bbp_get_template_part( 'pagination', 'replies' ); 
    endif;
    

    Remember to add the correct PHP tags before and after each line. Also included pastie with the entire post: Pastie with code


    FiveOneDigital
    Participant

    @fiveonedigital

    Hey,

    I did what you suggested, which is in essence just repeating the bbp_get_user_topics_started() function. However, I was not able to get this to output (I created a user-topics-replied.php file and used this for the replies loop, but it keeps outputting the “You have not replied to any topics” message I added in case it was empty.

    Were you able to get this to output?

    When I asked the question, I was wondering if there was anything built into bbPress 2.x that did something similar. I noticed another topic called “User Replied To?” but there was no answers.

    Its output was as expected using the replies loop, I assume you copied my function (there are some minor changes from bbp_get_user_topics_started)? Also, did you add the function to functions.php? Lastly, could you link a pastie.org of your user-topics-replied.php file?

    Just thought of something, could you check if the $user_id variable outputs the correct value? For example by doing a printf on the user variable on the same page you are trying to render the output.

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