WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] customizing list users (3 posts)

  1. alby54
    Member
    Posted 1 year ago #

    Hi I would like to modify this list user code

    $usernames = $wpdb->get_results("SELECT user_nicename, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
    
    foreach ($usernames as $username) {
        echo '<li><a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
    }

    so that admins are left out.
    Any help will be very appreciated
    thx

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I believe you can use the user_can() function like this (UNTESTED):

    $usernames = $wpdb->get_results("SELECT ID, user_nicename, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
    
    foreach ($usernames as $username) {
        if ( !user_can($username->ID,'administrator') ) {
           echo '<li><a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
       }
    }
  3. alby54
    Member
    Posted 1 year ago #

    Super! It works great..... ^__^

    Thx a lot vtxyzzy

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.