X

How to List Last Five Registered Users in WordPress

Snippets by IsItWP

Are you looking for a way to display the latest 5 registered members? While there’s probably a plugin for this, we have created a quick code snippet that you can use to list last five registered users in WordPress.

Instructions:

All you have to do is add this code to your theme’s index.php file:

<h2>Latest registered users</h2>
<ul>
<?php
$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>";
}
?>
</ul>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 43 best photography themes for WordPress and how to create a donation form in WordPress.

Comments   Leave a Reply

  1. This
    is a marvelous idea. However, can you give a brief overview as to how I would
    place this into a widget area?

  2. Tweets that mention Wordpress List last five registered users – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com January 29, 2011 at 6:49 pm

    […] This post was mentioned on Twitter by HN Firehose and wp_freak, WPSNIPP. WPSNIPP said: #wordpress List last five registered users http://bit.ly/hIBhfm #blog please RT 🙂 […]

  3. WordPress list last five registered users…

    Place this code in your WordPress theme to display the last five registered users….

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!