Ahmad
Ahmad

Reputation: 2129

how to list all users of a specific role on a page?

Is there any plugin for listing all the users of a specific role on a wordpress page.

I have searched for it but did not find any help.

Upvotes: 0

Views: 16379

Answers (4)

TARKUS
TARKUS

Reputation: 2200

My answer sort of launches off of @daz-reid 's answer. Notice that I'm filtering for a custom role called "member". This code works as of 4.2.3, on a GoDaddy shared WordPress Managed Hosting (mentioned because of the use of the server variable):

//Load WP API as its an external page
require_once( $_SERVER['CONTEXT_DOCUMENT_ROOT'] . '/' . 'wp-load.php' );

// Now have access to get_users
$membersArray = get_users( 'role=member' );

/*
These are the properties you can output:
[ID] => 4
[user_login] => josemborge
[user_pass] => $P$BIBdietTgVJlKqHuFGuOXWg5tWo56w.
[user_nicename] => josemeborge
[user_email] => [email protected]
[user_url] => 
[user_registered] => 2017-10-12 14:44:01
[user_activation_key] => 1507819441:$P$B7Hq4KOzrneDM1Bb0m.R94bQXFZKdj1
[user_status] => 0
[display_name] => Jose Borge
*/

//Now, to loop through the $membersArray and output each display_name:
foreach($membersArray as $member){
   echo $member->data->display_name . "<br>\n";
}

Upvotes: 2

Daz Reid
Daz Reid

Reputation: 1

i had a similar problem that involved doing the same but on a page external to wordpress. If it helps, here is what i did.

<?php 
    //Load WP API as its an external page 
    require 'blog/wp-load.php';

    // Now have access to get_users
    $membersArray = get_users( 'role=role-goes-here' );

    // Array of WP_User objects.
    foreach ( $bandMembers as $bandMember ){
      echo esc_html( $bandMember->nickname  )
    } 


?>

Hope it helps matey.

Upvotes: 0

Sam Kaz
Sam Kaz

Reputation: 450

The answer for your question has been well explained on this link http://wpengineer.com/365/list-all-users-in-wordpress/

Upvotes: 0

Zach
Zach

Reputation: 1964

I don't think there is a plugin for this so you might have to do this in php.

Check out this forum here

http://wordpress.org/support/topic/display-info-of-user-with-certain-role-or-level-ini-wp-27 specifically the last post with code in it by Jim de Groot.

He is doing the same thing as you want to it looks like.

If your confused by the code let me know and I can run you through it

Upvotes: 2

Related Questions