Family Encyclopedia >> Electronics

How to randomly show registered users in WordPress

Your users are the superstars of your multi-user WordPress site. There are many ways to highlight users and authors on your site. We previously showed you how to add an author info box and how to display recently registered users. In this article, we will show you how to display a random list of registered users in WordPress.

How to randomly show registered users in WordPress

The first thing you need to do is copy and paste the following code into your theme's functions.php file or a site-specific plugin.

 función wpb_random_users () global $ wpdb; $ randomusers = '
    '; // Base de datos de consultas para usuarios $ nombres de usuario = $ wpdb-> get_results ("SELECT user_nicename, user_url, user_email FROM $ wpdb-> usuarios ORDER BY RAND () LIMIT 5"); // Mostrar usuarios en una lista para cada ($ nombres de usuario como $ nombre de usuario) si (! $ Nombre de usuario-> usuario_url): $ usuarios aleatorios. = '
  • '.get_avatar ($ username-> user_email, 45). $ username-> user_nicename. "
  • "; else: $ randomusers. = '
  • '.get_avatar ($ username-> user_email, 45).' user_url. '">'. $ username-> user_nicename."
  • "; endif; $ randomusers. = '
'; devuelve $ randomusers; add_shortcode ('randomusers', 'wpb_random_users');

This code queries the WordPress users table in your database and selects a random row, then outputs the results to a bulleted list of the user's avatar and name. If a user has provided the website url in her profile, it will link the username to her website..

The next thing to do is display the list of registered users. To do this, all you need to do is add the following line of code to your theme file where you want the user list to display (such as sidebar.php, footer.php, etc.).

 

You can also display a list of random users from your site using this shortcode in a post, page or widget.

[usuarios aleatorios]

We hope this article helped you display a random list of registered users on your WordPress site. If you were looking to display a list of your staff members, you should check out this tutorial on how to create a staff list in WordPress.

If you have any questions or comments, please leave us a comment below. Also don't forget to follow us on Twitter and join Google.+