[wp-trac] [WordPress Trac] #22921: Allow get_users() to return array of values via 'fields' parameter
WordPress Trac
noreply at wordpress.org
Wed Jul 9 14:29:50 UTC 2025
#22921: Allow get_users() to return array of values via 'fields' parameter
-------------------------------------------------+-------------------------
Reporter: chipbennett | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Users | Version: 3.5
Severity: normal | Resolution:
Keywords: has-patch needs-testing dev- | Focuses:
feedback needs-refresh close |
-------------------------------------------------+-------------------------
Changes (by callumbw95):
* keywords: has-patch needs-testing dev-feedback needs-refresh => has-
patch needs-testing dev-feedback needs-refresh close
Comment:
Hey all,
I have just tested this one today in the latest release, and specifically
I tested the code that @lucasbustamante submitted last, and this appears
to be working in the suggested way now.
So as before:
{{{#!php
<?php
$admins = get_users([
'role' => 'administrator',
'fields' => [
'user_email'
],
]);
// Returns
array [
0 => object(stdClass) [
'user_email' => string 'test at wordpress.com',
],
];
// accessible via $admins[0]->user_email
}}}
However now without passing an array to fields you get just the requested
field returned in an array, which is what I believe we were originally
after:
{{{#!php
<?php
$admins = get_users([
'role' => 'administrator',
'fields' => 'user_email',
]);
// Returns
array [
0 => string 'callum.bridgford-whittick at wpengine.com'
]
}}}
As this issue seems to be solved in the current state of WordPress, I
believe this ticket can be closed, and as of such I have attached the
`close` tag.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/22921#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list