Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding Roles from the member loop!


  • perywinkle
    Participant

    @perywinkle

    Been wanting to exclude users with the role ‘subscriber’ from the member directory.
    I’ve been looking around for this for a while. I think I may have found it!
    Editing the members-loop.php like so:

    `

      <?php while ( bp_members() ) : bp_the_member();
      $user = new WP_User( bp_get_member_user_id() );
      if ( $user->roles[0] != ‘subscriber’ ) :
      ?>

    `

    Correct me if I’m wrong… !?

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

  • WayLay Design
    Participant

    @waylaydesign

    Perfect! This DOES remove Subscriber users from the member directory. Such an easy fix. Thanks!

    But how can one exclude administrator? What is his role[?]

    never mind, I found
    User Level 8 converts to Administrator
    User Level 9 converts to Administrator
    User Level 10 converts to Administrator

    EDIT: No, it doesn’t work


    cwulff
    Participant

    @cwulff

    How would you modify this to be just one group? I tried changing

    if ( $user->roles[0] != ‘subscriber’ ) : to if ( $user->roles[0] = ‘moderator’ ) :

    but it seems to still include everyone (or at least moderators as well as administrators – those are the only roles I’m currently using).

    Thoughts?


    4ella
    Participant

    @4ella

    Hello , I have 2 questions :
    1. How do you include only subscribers ? It means I would like to have only subscribers directory and ignore other roles.
    2. How do you exclude more roles as for example subscribers + editors + moderators ? it means how should look like a code for more than 1 role?


    cwulff
    Participant

    @cwulff

    If you want to include just one role change

    if ( $user->roles[0] != ‘subscriber’ ) :

    to

    if ( $user->roles[0] == ‘subscriber’ ) :

    or

    if ( $user->roles[0] == ‘moderator’ ) :


    razzgpe
    Participant

    @razzgpe

    Yeah, how can I add member roles to the members loop?

    For example this menu:

    All members | Persons | Companys | Universitiys | Other


    landwire
    Participant

    @landwire

    Hi there,
    exactly looking for the same stuff!


    johnhiemstra
    Member

    @johnhiemstra

    thanks for this code, answers my next need in current BP project. in answer to last two questions, try this plugin I found: https://wordpress.org/extend/plugins/advanced-access-manager/ has allowed me to create custom BP roles recognized by BP core and other plug-ins like Justin Tadlock’s roles-at-registration, role-scoper, etc.


    perywinkle
    Participant

    @perywinkle

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Excluding Roles from the member loop!’ is closed to new replies.
Skip to toolbar