Skip to:
Content
Pages
Categories
Search
Top
Bottom

List all users with a specific role


  • Rourke
    Participant

    @rourke

    I want to separately list all users that have the roles Keymaster, Moderator and a custom role Blogger. How would I be able to do this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi Rourke,

    If you just want to list them in the backend, you could use https://wordpress.org/plugins/bbp-manage-subscriptions/

    Pascal.


    Rourke
    Participant

    @rourke

    Thanks Pascal,

    I’m actually making a shortcode to format a list of users that have the earlier mentioned roles. This shortcode will be used on a page for the front-end.

    It’s basically a list of site staff members.

    Ah ok,

    Then how about:
    $mykeymasters = get_users( array('role' => 'keymaster') );

    https://codex.wordpress.org/Function_Reference/get_users

    Pascal.


    Rourke
    Participant

    @rourke

    But isn’t that for the wordpress roles? Because that returns 0 users.

    The roles I’m talking about are the ones you specify at the bottom of a profile page. Forum roles. Apologies if I wasn’t specific enough.

    Euh, yes of course.

    Can this help you then ?

    $user_query_full = new WP_User_Query( array( 'role' => 'bbp_keymaster' ) );
    $user_query = $user_query_full->get_results();
    var_dump( $user_query );

    Pascal.


    Rourke
    Participant

    @rourke

    Ah! The difference was the bbp_keymaster instead of the keymaster. This worked for me:

    $mykeymasters = get_users( array('role' => 'keymaster') );

    Thanks Pascal! You really helped me out here 🙂

    Glad I was of any help.

    Enjoy bbPress !

    Pascal.


    Rourke
    Participant

    @rourke

    Oops, I copy/pasted but forgot to edit the line. This is the correct one for anyone else trying to do this in the future:

    $mykeymasters = get_users( array('role' => 'bbp_keymaster') );

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