Codex tools: Log in
Contents |
The WordPress User Query class allows querying the user database and deprecates the WP_User_Search class since Version 3.1.
<?php $codex_users = new WP_User_Query( parameters ) ?>
The WP_User_Query constructor allows the following parameters
Either an array of row objects with properties corresponding to the wp_users table column names specified in 'fields' or, if 'fields' equals 'all_with_meta', an array of WP_User objects.
The default value for 'fields' is 'all' which will return all columns of the wp_users table in an array of row objects.
List all blog editors:
$wp_user_search = new WP_User_Query( array( 'role' => 'editor' ) ); $editors = $wp_user_search->get_results();
List all blog editors, return WP_User objects:
$wp_user_search = new WP_User_Query( array( 'role' => 'editor', 'fields' => 'all_with_meta' ) ); $editors = $wp_user_search->get_results();
List all blog editors, return limited fields in resulting row objects:
$args = array(); $args[0] = 'user_login'; $args[1] = 'user_nicename'; $args[2] = 'user_email'; $args[3] = 'user_url'; $wp_user_search = new WP_User_Query( array( 'role' => 'editor', 'fields' => $args ) ); $editors = $wp_user_search->get_results();
class and function WP_User_Query is located in wp-includes/user.php.
http://codex.wordpress.org/Database_Description#Table%3a_wp_users_2
http://codex.wordpress.org/Class_Reference/WP_User