Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to create a list of all the alphabets that represent each user in my site.

Example:

A -> Link that shows list of all users whose **nickname** starting with letter "A"
B -> ...starting with letter "B"
C -> ...starting with letter "C"
D -> ...starting with letter "D"
E -> ...starting with letter "E"
F -> ...starting with letter "F"
.
.
Z -> ...starting with letter "Z"

I would like to list every alphabet regardless of if there is or isn't a user for it. But would also to know how to only show alphabets with users. Im not sure exactly which method I'll end up using, but I just want to have the option.

Ive searched online but couldnt find anything for my particular situation.

Id appreciate any help with this. Thanks a lot

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There's the WP_User_Query for that:

/**
 * List all Users
 * Use as: Template Tag
 * 
 * @uses WP_User_Query
 * @return (array) List of user objects
 */
wpse35713_get_users_list()
{
    $query = new WP_User_Query( array(
         'order'    => 'ASC'
        ,'orderby'  => 'login'
    ) );
    $users = $query->get_results();

    $html  = "<ul><li>";
    foreach ( $users as $user )
    {
        $html .= "</li><li>{$user}";
    }
    $html .= "</li><ul>";

    return $html;
}
share|improve this answer
1  
Thank you, I'll try it out! –  user1893 Dec 6 '11 at 22:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.