Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


  • graymerica
    Member

    @graymerica

    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,

    thanks,

    Andrew

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

  • landwire
    Participant

    @landwire

    Hey there,
    I looking for a solution to that too! Any answers yet?


    gingram815
    Member

    @gingram815

    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’).
    `<?php

    $twamembers = get_users(‘role=s2member_level1&fields=ID’);
    $admin = get_users(‘role=administrator&fields=ID’);
    $role_ids=array_merge($twamembers,$admin);
    $value=implode(‘,’,$role_ids);

    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