WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Authors page (3 posts)

  1. timmykins
    Member
    Posted 2 years ago #

    Hi wonder if someone can help with this.

    I have spent most of today trying to solve this but can't so I hope someone here can help.

    I have created a custom page to show details of contributors and authors using code that I found here, but when I show the page it shows a list of all registered users, no matter what their role is.

    Does anyone know how I can modify this code to just show contributors, authors and select admins. I know the answer is in the SQL query but my PHP and SQL aren't that great!

    function contributors() {

    global $wpdb;
    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY display_name");
    foreach ($authors as $author ) {
    echo "

  2. ";
    echo '<div>';
    echo get_avatar($author->ID);
    echo "</div>";
    echo '<div>';
    echo "";
    echo the_author_meta('display_name', $author->ID);
    echo "
    ";
    echo "
    ";echo "
    ";
    echo the_author_meta('user_description', $author->ID);
    echo "
    ";
    echo "</div>";
    echo "
  3. ";
    echo "
    ";
    }
    }

    Thanks in advance.

  • bcworkz
    Member
    Posted 2 years ago #

    I'm pretty weak on SQL syntax too, so I can't give you a total answer, but a different approach that may work better for you is to get_var the user_id in usermeta table WHERE meta_key = 'wp_capabilities' AND (meta_value = 'contributor OR meta_value = 'author').

    Even though the key is wp_capabilities, it is actually storing roles. The other thing you'll have to figure out is the stored capability-but-actually-role value is actually an array, not a string as I had shown above. Sorry, I don't know how to query for an array element, but the first element should be a string as shown above.

    You can then step through the user IDs returned and display whatever data you want for each ID

  • timmykins
    Member
    Posted 2 years ago #

    Thanks for your response. I am still working on this, and it's driving me crazy! I did find a plugin, WordPress User, that does what I need, but as usual not quite!

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.