The get_author_user_ids() WordPress PHP function retrieves all user IDs.
Usage
$all_user_ids = get_author_user_ids();
Parameters
- None
More information
See WordPress Developer Resources: get_author_user_ids
Examples
Display a list of all user names
Retrieve all user IDs and display their corresponding names.
$all_user_ids = get_author_user_ids();
foreach ($all_user_ids as $user_id) {
$user_info = get_userdata($user_id);
echo $user_info->display_name . '<br>';
}
Count total number of users
Calculate the total number of users on the site.
$all_user_ids = get_author_user_ids(); $total_users = count($all_user_ids); echo 'Total Users: ' . $total_users;
Get all users with a specific role
Retrieve all user IDs with the role of ‘editor’.
$all_user_ids = get_author_user_ids();
$editors = array();
foreach ($all_user_ids as $user_id) {
$user = new WP_User($user_id);
if (in_array('editor', $user->roles)) {
$editors[] = $user_id;
}
}
print_r($editors);
Display author names alphabetically
Retrieve all user IDs and display their names in alphabetical order.
$all_user_ids = get_author_user_ids();
$author_names = array();
foreach ($all_user_ids as $user_id) {
$user_info = get_userdata($user_id);
$author_names[] = $user_info->display_name;
}
sort($author_names);
foreach ($author_names as $name) {
echo $name . '<br>';
}
Get user email addresses
Retrieve all user IDs and display their email addresses.
$all_user_ids = get_author_user_ids();
foreach ($all_user_ids as $user_id) {
$user_info = get_userdata($user_id);
echo $user_info->user_email . '<br>';
}