You’re probably better off to use get_users
which returns an array of
<?php
// get all users, regardless of roll. If you do need to restrict by
// role you can use the `role` argument: get_users(array('role' => 'author'));
$uses = get_users(array('orderby' => 'nicename'));
foreach ($users as $user) {
// do stuff with $user, will have all the usual stuff, ID, user_email, etc
echo '<p>', esc_html($user->ID), '</p>';
}
Alternatively, you can use the all_with_meta
argument for the fields
argument of get_users
and get an array of WP_User
objects back:
<?php
$users = get_users(array('fields' => 'all_with_meta'));
foreach ($users as $user) {
// $user will be a WP_User object.
}
Is there a way to only select users with specific author meta fields filled out?
You can do this with get users as well! Just use the meta_query
argument, which looks the same as WP_Query
‘s meta_query argument.
<?php
$users = get_users(array(
'meta_query' => array(
array(
'key' => 'whatever_your_meta_key_is',
'value' => 'the_meta_value_you_want',
)
),
));
foreach ($users as $user) {
// do stuff with $user
}