Buddypress Pagination Recount Members

Hello,

I have created a buddypress site and have excluded certain users by role by adding some filters in members-loop.php and in groups/single/members.php. The issue is that the excluded members are not excluded by pagination count (Viewing 1-x active members). I have this code

function my_bp_get_members_pagination_count() {
    // Maybe modify $pag in some way.
    return $pag;
}
add_filter( 'bp_members_pagination_count', 'my_bp_get_members_pagination_count' );

but I do not know how to use it or build the appropriate $pag variable in order to make it work for members ang groups single page directory. Any ideas?

  • Sajid

    Hi Ioannis,
    Hope you are doing good today :slight_smile:

    I am sorry but I don't you can subtract something from the value give here because that is string instead of integer.

    Instead, try this code and then check again.

    add_filter('bp_get_total_member_count','bpdev_members_correct_count');
    function bpdev_members_correct_count($count){
    $excluded_users_count=1; //change it to the number of users you want to exclude
    return $count-$excluded_users_count;
    }

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid

  • Ioannis

    Hello Sajid,

    I tried excluding members by number with that code ( although is not exactly what I need) but it didn't work. In my website I have excluded users by role like admin or subscribers from the directories so I do not know the exact number of users that should be excluded from pagination recounting. I need a code that excludes members only by role not by number. Is there any other way to achieve that? What would you suggest?

    Thank you,
    Ioannis

  • Sajid

    Hi Ioannis,
    Hope you are doing good today :slight_smile:

    I think you need to change the you removed a user from members list to make that code work.

    Here is the full code including the above code snippet. Just replace number 1 in following line with your user ID(s).

    $excluded_user='1';//comma separated ids of users whom you want to exclude

    <?php
    // Remove admin from directory
    
    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    function bpdev_exclude_users($qs=false,$object=false){
     //list of users to exclude
    
     $excluded_user='1';//comma separated ids of users whom you want to exclude
    
     if($object!='members')//hide for members only
     return $qs;
    
     $args=wp_parse_args($qs);
    
     //check if we are listing friends?, do not exclude in this case
     if(!empty($args['user_id']))
     return $qs;
    
     if(!empty($args['exclude']))
     $args['exclude']=$args['exclude'].','.$excluded_user;
     else
     $args['exclude']=$excluded_user;
    
     $qs=build_query($args);
    
     return $qs;
    
    }
    
    //Remove admin from member count
    
    add_filter('bp_get_total_member_count','bpdev_members_correct_count');
    function bpdev_members_correct_count($count){
    $excluded_users_count=1; //change it to the number of users you want to exclude
    return $count-$excluded_users_count;
    }

    That does not matter if you are excluding by role or not, we just need number of users that you want to remove and that's it.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,
    Sajid

  • Ioannis

    Hello Sajid,

    I have made a buddypress site where i will have a lot of users where their roles will be changing propably every month. So it would be impossible for me to check every month which ids have what role and adding that ids to the snippet. As I unterstand there is no way to hide users from recounting only by role. Anyway thank you very very much for your support, I may use your code in a future project.

    Kind Regards,
    Ioannis

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.