Skip to:

Limiting BP_members to show only certain user levels (no subscriber or admin)

  • Does anyone know how to filter all member lists in Buddypress to only show users with the role of author or higher.

    I do not want subscriber level users to show up in the member lists or the count

    I have looked at the bp_has_members function and can not find a way to do it. I have also looked all over various filters available and I am stumped.

    I have written the following code:
    add_filter( ‘bp_core_get_paged_users_sql’, ‘bp_filter_only_members’ , 1, 9 );
    add_filter( ‘bp_core_get_total_users_sql’, ‘bp_filter_only_members’ , 1, 9 );

    function bp_filter_only_members($sql, $object) {
    $sql = str_replace(‘FROM’ , “,(SELECT meta_value FROM wp_usermeta WHERE meta_key = ‘wp_user_level’ AND user_id = u.ID) AS user_level FROM” , $sql ) ;
    $sql = str_replace(‘ORDER BY’ , “HAVING user_level > 1 ORDER BY” , $sql) ;
    return $sql;
    The issue I am having is that the count is coming back wrong.

    Can anyone think of a better way than going directly to the SQL. I have thought about meta values and some other hacky ways of doing this,

    can anyone help me out on this,



Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey there,
    I looking for a solution to that too! Any answers yet?

    I am having the exact same issue. I tried modifying bp_has_members but I can’t figure out how to integrate with bp_ajax_querystring( ‘members’).

    $twamembers = get_users(‘role=s2member_level1&fields=ID’);
    $admin = get_users(‘role=administrator&fields=ID’);

    if ( bp_has_members(‘type=alphabetical&include=’.$value) ) : ?>`
    The above code returns the members I want in the member directory, but then I cannot search the directory. Does anyone know how to either search the member directory without the ajax or integrate the above with the ajax so they work together?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limiting BP_members to show only certain user levels (no subscriber or admin)’ is closed to new replies.
Skip to toolbar