Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Retrieve Registered Users From the Database

Posted on May 19, 2011 by Pippin in Intermediate, Quick Tips, Tutorials, WordPress Database 1 Comment
Home» Tutorials » Intermediate » Retrieve Registered Users From the Database
Tweet
Love It - 0

This useful little tip will show you how to retrieve an array of registered users from your WordPress database. We will use the get_users() function to query the database and return an array of users matching our parameters.

As defined in the codex, here is the function and all of its accepted parameters:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php $args = array(
	'blog_id' => $GLOBALS['blog_id'],
	'role' => ,
	'meta_key' => ,
	'meta_value' => ,
	'meta_compare' => ,
	'include' => array(),
	'exclude' => array(),
	'orderby' => 'login',
	'order' => 'ASC',
	'offset' => ,
	'search' => ,
	'number' => ,
	'count_total' => true,
	'fields' => 'all',
	'who' => 
 ); ?>
 
<?php get_users( $args ); ?>

So, for example, if we are running a multi site blog network, then we could do the following to retrieve all of the users from blog ID 2, excluding the admin user, and then store their emails in another array:

1
2
3
4
5
 
$registered_users = get_users(array('blog_id' => 2, 'exclude' => array(1) ));
foreach ($registered_users as $user) {
	$user_emails[] = $user->user_email;
}
This is a great trick to use for email notification plugins, such as Post Notify
Tweet Follow @pippinsplugins
blog, database, users

One comment on “Retrieve Registered Users From the Database”

  1. http://www.pishro-music.com/better-fashion-and-style-with-help-from-kasper-suits/57/ says:
    July 24, 2011 at 1:47 pm

    Clubpenguin…

    [...]right here are a couple of urls to websites online we connect to as we feel these are worth browsing[...]…

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • User Follow System – Part 1
  • User Bookmarks for WordPress
  • User Submitted Image Gallery – Part 3
  • User Submitted Gallery Images – Part 2
  • User Submitting Gallery Images – Part 1

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Test Your Plugins with RTL (0)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • @corymiller303 I hope everything with the surgery went well!
    May 25, 2013
  • RT @strickland: To celebrate Memorial Day weekend @gittyapp is on sale through Monday. Now is the time to join in! http://t.co/vOAqksLLrN
    May 25, 2013
  • RT @GaryJ: Premium theme sellers: consider spending 30mins to add an rtl.css to your themes, to considerably open up your potential market.
    May 25, 2013

Topics

register_setting contextual help attachments add_shortcode hook featured campaign monitor wp_enqueue_script Rémi Corson shortcodes the_content get_user_meta Sugar Event Calendar plugin authors attachment image forms login short codes do_action Related posts mail chimp comments recent posts post types apply_filters bbpress short code taxonomies custom post type gallery Ajax images Stripe taxonomy jquery users widgets add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins