你最好使用get_users
返回
<?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>\';
}
或者,您可以使用
all_with_meta
的参数
fields
的参数
get_users
并获取
WP_User
对象返回:
<?php
$users = get_users(array(\'fields\' => \'all_with_meta\'));
foreach ($users as $user) {
// $user will be a WP_User object.
}
有没有办法只选择填写了特定作者元字段的用户?
您也可以通过“获取用户”来实现这一点!只需使用meta_query
参数,看起来与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
}