WordPress.org

Ready to get started?Download WordPress

Forums

list users by role (4 posts)

  1. gucapi
    Member
    Posted 6 years ago #

    hi!

    i use the tag wp_list_authors(); to list my users on page!

    but i want that this list is sorting by role:

    role 1:
    - user 1
    - user 7
    - user 4

    role 2:
    - user 2
    - user 3
    - user 5

    etc

    but this tag only show user sorting [A-Z]

    any idea?

  2. sasch9r
    Member
    Posted 6 years ago #

    Hm, can't find a function to get users' roles but you can write your own mysql query or write the list by hand.

  3. sivac
    Member
    Posted 6 years ago #

    Hi

    try this code, let me know if u have any questions?

    $users_of_blog = get_users_of_blog();

    //var_dump($users_of_blog);
    $contributor = array();
    $subscriber = array();
    $author = array();
    foreach ( (array) $users_of_blog as $b_user ) {

    $b_roles = unserialize($b_user->meta_value);
    foreach ( (array) $b_roles as $b_role => $val ) {

    if($b_role=='contributor'){
    array_push($contributor,$b_user->display_name);
    }
    if($b_role=='subscriber'){
    array_push($subscriber,$b_user->display_name);
    }
    if($b_role=='author'){
    array_push($author,$b_user->display_name);
    }

    }
    }

    <table width="100" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td align="left">Contributors</td>
    <td> </td>
    </tr>
    <?php
    $ccount = count($contributor);

    for ($i = 0; $i <= $ccount; $i++) {

    ?>
    <tr>
    <td align="left"><?php echo $contributor[$i]?></td>
    <td> </td>
    </tr>
    <?php } ?>
    <tr>
    <td> </td>
    <td> </td>
    </tr>
    </table>

  4. Troy Dean
    Member
    Posted 5 years ago #

    Sivac,

    Thankyou for the contribution. This is exactly what I needed to finish an application for staff rosters. Might make a useful plugin too.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic