WordPress.org

Forums

Users, Roles and Sidebar choices (1 post)

  1. KB2012
    Member
    Posted 2 years ago #

    Hi everyone,
    I have been trying to figure this one out but have not been able to, so hoping someone here will have a working solution.
    On the users.php, I have all registered users listed. The goal is to have them listed alphabetically, by last name, with a choice menu in the sidebar for only listing users of a particular role - the choice will be a link in the sidebar. One of the choices will be "All", to show all users, again, in alphabetical order. This is very similar to categories in terms of posts/articles.
    Also, I need to either hide/exclude all users who are missing a last name and/or avatar, or order them in a way for the users who do have a last name/avatar to show on top of the page.
    The current code only pulls the subscribers list, and I have not been able to sort them. From what I found here and elsewhere, it has something to do with the first_name and last_name being meta keys with different values for each user?

    Here is the code currently in use:

    function contributors() {
    global $wpdb;

    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name ");

    foreach($authors as $author) {
    echo '<div class="item">';
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">"; //end link//
    echo get_avatar($author->ID);
    echo "";
    the_author_meta('display_name', $author->ID);
    echo "";
    echo "</div>";
    }
    }

    Link

    Here is the code I have been testing and allows for manual reorder of the roles, but the "All" link is pulling all roles, including subscribers, causing duplicate entries when All is selected. Other sidebar choices are working but, but the sorting does not:

    function kontributors() {
    global $wpdb;

    $authors = $wpdb->get_results("SELECT user_id from $wpdb->usermeta WHERE meta_key = 'last_name' ORDER BY meta_value order='ASC'&role=administrator editor author vlogger blogger videographer ocblogger studentemployee subscriber");

    foreach ($authors as $author) {
    echo '<div class="item">';
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">"; //end link//
    echo get_avatar($author->ID);
    echo "";
    the_author_meta('display_name', $author->ID);
    echo "";
    echo "</div>";
    }

    $blogusers = get_users("order='DESC'&role=administrator"); /*not working with "SELECT user_id..." as for other roles*/
    foreach ($blogusers as $author) {
    echo '<div class="item administrator">';
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">"; //end link//
    echo get_avatar($author->ID);
    echo "";
    the_author_meta('display_name', $author->ID);
    echo "";
    echo "</div>";
    }

    $blogusers = get_users("SELECT user_id from $wpdb->usermeta WHERE meta_key = 'last_name' ORDER BY meta_value order='ASC'&role=editor");
    foreach ($blogusers as $author) {
    echo '<div class="item editor">';
    echo "<a href=\"".get_bloginfo('url')."/?author=";
    echo $author->ID;
    echo "\">"; //end link//
    echo get_avatar($author->ID);
    echo "";
    the_author_meta('display_name', $author->ID);
    echo "";
    echo "</div>";
    }
    }

    The above "$blogusers = get_users..." is used for all other roles, including subscribers.

    And here is the code in the sidebar PHP Code widget:

    <ul id="filterOptions">
    <li class="active">All

  2. Administrator
  3. Editor
  4. Author
  5. Subscriber
  6. Vlogger
  7. Blogger
  8. OnCampus Blogger
  9. Student Employee
  10. Link
    Any info would be appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic