Display user data by user role

<?php
//list each role and each user with that role
global $wp_roles;
foreach( $wp_roles->role_names as $role => $name ) {
$name = translate_with_context($name);
if($name == ‘Agent’){
echo ‘<p>List of users in the role ‘.$role .’ (‘. $name . ‘):</p>’;
$this_role = “‘[[:<:]]”.$role.”[[:>:]]'”;
$query = “SELECT * FROM $wpdb->users WHERE ID = ANY (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = ‘wp_capabilities’ AND meta_value RLIKE $this_role) ORDER BY user_nicename ASC LIMIT 10000″;
$users_of_this_role = $wpdb->get_results($query);
if ($users_of_this_role) {
foreach($users_of_this_role as $user) {
$curuser = get_userdata($user->ID);
$author_post_url=get_author_posts_url($curuser->ID, $curuser->nicename);
echo ‘<p>–User nicename: ‘.$curuser->user_nicename .’, display Name: ‘. $curuser->display_name . ‘, link to author posts <a href=”‘ . $author_post_url . ‘” title=”‘ . sprintf( __( “Posts by %s” ), $curuser->user_nicename ) . ‘” ‘ . ‘>’ . $curuser->user_nicename .'</a></p>’;
}
}
}
}
?>

 

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: