Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filter the Activity Loop for Specific User Updates


  • colingdi
    Participant

    @colingdi

    Hi,
    So for our sins we’ve customised our profile page to be a lot different to the core (not by choice), this works great bar a few anomalies. I’m trying to filter the activity loop to just show the displayed users posts. I’ve written up the code as follows:

    if ( bp_has_activities( $activity_id . '&user_id='.$userToFilter.'&scope=just-me&action="activity_update"&max=3&page_arg="true"' ) )

    This gives me a loop of just 3 items (so some of it is being listened to!) but no pagination and no filtering on the displayed user (which is the value $userToFilter). I’ve echoed out the filter and it’s reading as: &user_id=1&scope=just-me&action=”activity_update”&max=3&page_arg=”true” which I think is right. Any guidance greatly appreciated, I tried the plugin for activity shortcode and got the same results weirdly.

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

  • Henry Wright
    Moderator

    @henrywright

    Try using bp_parse_args(). Here is an example:

    
    function my_filter_after_has_activities_parse_args( $r ) {
        $r['per_page'] = 3;
        // Do something else here
        return $r;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_filter_after_has_activities_parse_args' );
    

    See https://codex.buddypress.org/developer/using-bp_parse_args-to-filter-buddypress-template-loops/


    colingdi
    Participant

    @colingdi

    That helped a lot, I’ve now got it filtering for the users activity on just their profile page. So we’re halfway there. Using your links I’m to the point where I have this code:

    function my_filter_after_has_activities_parse_args( $r ) {
            $r['per_page'] = 10;
            if (bp_is_my_profile()) {
            $r['per_page'] = 3;
            $r['scope'] = "just-me";
            } else if (bp_is_user_profile()) {
            $r['per_page'] = 3;
            //$r['scope'] = "just-me"; - I'll work out the code for just-them after I get the function calling
            }
            
            return $r;
        }
        add_filter( 'bp_after_has_activities_parse_args', 'my_filter_after_has_activities_parse_args' );

    When I run this code on a normal users profile I get nothing changed (the final bp_is_user_profile() doesn’t fire). I’m on the site.com/members/user page and it’s the ‘home.php’ template that’s calling all of this so I’m at a loss as to why I’m getting no joy.


    shanebp
    Moderator

    @shanebp

    Try replacing bp_is_user_profile() with bp_is_user()


    colingdi
    Participant

    @colingdi

    Thanks to both of you, between the two responses you solved what was a headache and a half!


    shadab Awan
    Participant

    @shadab7080

    thank Henry Wright for help i was also looking for someone to answer this question and to guide me


    Doa Islam
    Participant

    @doaislam

    Henry thanks a lot that solution of yours help me out from the problem.

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