get_users(…) only returns one user2019 Community Moderator ElectionBest way to get user id for get_users function?Get multiple roles with get_usersget_users is expecting unserialized meta_valueHow to do get_users() with multiple meta_keysHow to get the user description with get_users?get_users meta_querySort get_users by custom fieldget_users() ORDER BY Not WorkingGet_Users Orderby Pageget_users by role returns all users
Update Cursor skipping last row?
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Java: Is there a common interface or superclass for arrays and collections?
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
Symbol above others
Query a database specific configuration parameter
Is it worth rebuilding a wheel myself to save money?
What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?
Can I legally use front facing blue light in the UK?
aging parents with no investments
Is "plugging out" electronic devices an American expression?
How to move the player while also allowing forces to affect it
"My colleague's body is amazing"
How can I fix this gap between bookcases I made?
Are there any other methods to apply to solving simultaneous equations?
Email Account under attack (really) - anything I can do?
Doomsday-clock for my fantasy planet
Is std::next for vector O(n) or O(1)?
Where does the Shulchan Aruch quote an authority by name?
Why do we use polarized capacitors?
Is it possible for the two major parties in the UK to form a coalition with each other instead of a much smaller party?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Explicitly parse JSON string vs JSON.deserialize
get_users(…) only returns one user
2019 Community Moderator ElectionBest way to get user id for get_users function?Get multiple roles with get_usersget_users is expecting unserialized meta_valueHow to do get_users() with multiple meta_keysHow to get the user description with get_users?get_users meta_querySort get_users by custom fieldget_users() ORDER BY Not WorkingGet_Users Orderby Pageget_users by role returns all users
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...)
is only returning me 1 users though it should return 3. What am I doing wrong?
var_dump($targetUsersIDs);
$targetUsers = get_users(['include' => $targetUsersIDs]);
var_dump($targetUsers);
Output of var_dump($targetUsersIDs);
array (size=3)
0 =>
object(stdClass)[4785]
public 'ID' => string '1' (length=1)
1 =>
object(stdClass)[4784]
public 'ID' => string '2' (length=1)
2 =>
object(stdClass)[4783]
public 'ID' => string '4' (length=1)
Start of the output of var_dump(targetUsers);
array (size=1)
0 =>
object(WP_User) ...
php id get-users
New contributor
add a comment |
I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...)
is only returning me 1 users though it should return 3. What am I doing wrong?
var_dump($targetUsersIDs);
$targetUsers = get_users(['include' => $targetUsersIDs]);
var_dump($targetUsers);
Output of var_dump($targetUsersIDs);
array (size=3)
0 =>
object(stdClass)[4785]
public 'ID' => string '1' (length=1)
1 =>
object(stdClass)[4784]
public 'ID' => string '2' (length=1)
2 =>
object(stdClass)[4783]
public 'ID' => string '4' (length=1)
Start of the output of var_dump(targetUsers);
array (size=1)
0 =>
object(WP_User) ...
php id get-users
New contributor
add a comment |
I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...)
is only returning me 1 users though it should return 3. What am I doing wrong?
var_dump($targetUsersIDs);
$targetUsers = get_users(['include' => $targetUsersIDs]);
var_dump($targetUsers);
Output of var_dump($targetUsersIDs);
array (size=3)
0 =>
object(stdClass)[4785]
public 'ID' => string '1' (length=1)
1 =>
object(stdClass)[4784]
public 'ID' => string '2' (length=1)
2 =>
object(stdClass)[4783]
public 'ID' => string '4' (length=1)
Start of the output of var_dump(targetUsers);
array (size=1)
0 =>
object(WP_User) ...
php id get-users
New contributor
I have an array of user IDs, I want to get data for each of these users. I first thought of writing a classic SQL query but I found WordPress has integreted functions for it. However, get_users(...)
is only returning me 1 users though it should return 3. What am I doing wrong?
var_dump($targetUsersIDs);
$targetUsers = get_users(['include' => $targetUsersIDs]);
var_dump($targetUsers);
Output of var_dump($targetUsersIDs);
array (size=3)
0 =>
object(stdClass)[4785]
public 'ID' => string '1' (length=1)
1 =>
object(stdClass)[4784]
public 'ID' => string '2' (length=1)
2 =>
object(stdClass)[4783]
public 'ID' => string '4' (length=1)
Start of the output of var_dump(targetUsers);
array (size=1)
0 =>
object(WP_User) ...
php id get-users
php id get-users
New contributor
New contributor
edited 33 mins ago
leymannx
74911022
74911022
New contributor
asked 3 hours ago
TTTTTT
1216
1216
New contributor
New contributor
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
The include
key on get_users
requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.
New contributor
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
add a comment |
Somebody has posted this solution and then deleted their post:
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
It is where I'm using right now.
Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).
New contributor
Julian's answer explains you why you only got one user returned. Now there'swp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly whatinclude
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the$targetUsersIDs
array came from in the first place.
– leymannx
29 mins ago
add a comment |
Do it like this
var_dump($targetUsersIDs);
$ids = array();
foreach ( $targetUsersIDs as $id ) $ids[] = $id;
$targetUsers = get_users(['include' => $ids ] );
var_dump($targetUsers);
I hope this may help.
add a comment |
You should be using WP_User_Query
for this.
$user_ids = [ 1, 2, 3, 4, 5 ];
$args = [
'include' = $user_ids,
]
$user_query = new WP_User_Query( $args );
Now you can simply use the result in a user loop/foreach.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "110"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
TTT is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333863%2fget-users-only-returns-one-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The include
key on get_users
requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.
New contributor
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
add a comment |
The include
key on get_users
requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.
New contributor
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
add a comment |
The include
key on get_users
requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.
New contributor
The include
key on get_users
requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you want.
New contributor
New contributor
answered 2 hours ago
JulianJulian
1213
1213
New contributor
New contributor
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
add a comment |
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
I guess it's the right path ... now, looping on the array for($i=0; $i < $targetUsersIDsCount;$i++) $integerTargetUsersIDs[$i] = (int)$targetUsersIDs[$i]; Gives me and array of 3 times 1 (integer)
– TTT
2 hours ago
add a comment |
Somebody has posted this solution and then deleted their post:
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
It is where I'm using right now.
Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).
New contributor
Julian's answer explains you why you only got one user returned. Now there'swp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly whatinclude
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the$targetUsersIDs
array came from in the first place.
– leymannx
29 mins ago
add a comment |
Somebody has posted this solution and then deleted their post:
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
It is where I'm using right now.
Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).
New contributor
Julian's answer explains you why you only got one user returned. Now there'swp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly whatinclude
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the$targetUsersIDs
array came from in the first place.
– leymannx
29 mins ago
add a comment |
Somebody has posted this solution and then deleted their post:
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
It is where I'm using right now.
Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).
New contributor
Somebody has posted this solution and then deleted their post:
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
It is where I'm using right now.
Please dn't hesitate to tell me if there's any reason it was wrong (I'm not sure the user has deleted their answer).
New contributor
New contributor
answered 44 mins ago
TTTTTT
1216
1216
New contributor
New contributor
Julian's answer explains you why you only got one user returned. Now there'swp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly whatinclude
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the$targetUsersIDs
array came from in the first place.
– leymannx
29 mins ago
add a comment |
Julian's answer explains you why you only got one user returned. Now there'swp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly whatinclude
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the$targetUsersIDs
array came from in the first place.
– leymannx
29 mins ago
Julian's answer explains you why you only got one user returned. Now there's
wp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly what include
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs
array came from in the first place.– leymannx
29 mins ago
Julian's answer explains you why you only got one user returned. Now there's
wp_list_pluck()
with which you get an array existing merely of user IDs. Which is exactly what include
is expecting. Wondering myself why the answer got deleted. It looks just fine. Maybe they were worried about where the $targetUsersIDs
array came from in the first place.– leymannx
29 mins ago
add a comment |
Do it like this
var_dump($targetUsersIDs);
$ids = array();
foreach ( $targetUsersIDs as $id ) $ids[] = $id;
$targetUsers = get_users(['include' => $ids ] );
var_dump($targetUsers);
I hope this may help.
add a comment |
Do it like this
var_dump($targetUsersIDs);
$ids = array();
foreach ( $targetUsersIDs as $id ) $ids[] = $id;
$targetUsers = get_users(['include' => $ids ] );
var_dump($targetUsers);
I hope this may help.
add a comment |
Do it like this
var_dump($targetUsersIDs);
$ids = array();
foreach ( $targetUsersIDs as $id ) $ids[] = $id;
$targetUsers = get_users(['include' => $ids ] );
var_dump($targetUsers);
I hope this may help.
Do it like this
var_dump($targetUsersIDs);
$ids = array();
foreach ( $targetUsersIDs as $id ) $ids[] = $id;
$targetUsers = get_users(['include' => $ids ] );
var_dump($targetUsers);
I hope this may help.
edited 2 hours ago
answered 2 hours ago
Qaisar FerozQaisar Feroz
1,4071217
1,4071217
add a comment |
add a comment |
You should be using WP_User_Query
for this.
$user_ids = [ 1, 2, 3, 4, 5 ];
$args = [
'include' = $user_ids,
]
$user_query = new WP_User_Query( $args );
Now you can simply use the result in a user loop/foreach.
add a comment |
You should be using WP_User_Query
for this.
$user_ids = [ 1, 2, 3, 4, 5 ];
$args = [
'include' = $user_ids,
]
$user_query = new WP_User_Query( $args );
Now you can simply use the result in a user loop/foreach.
add a comment |
You should be using WP_User_Query
for this.
$user_ids = [ 1, 2, 3, 4, 5 ];
$args = [
'include' = $user_ids,
]
$user_query = new WP_User_Query( $args );
Now you can simply use the result in a user loop/foreach.
You should be using WP_User_Query
for this.
$user_ids = [ 1, 2, 3, 4, 5 ];
$args = [
'include' = $user_ids,
]
$user_query = new WP_User_Query( $args );
Now you can simply use the result in a user loop/foreach.
answered 47 mins ago
leymannxleymannx
74911022
74911022
add a comment |
add a comment |
TTT is a new contributor. Be nice, and check out our Code of Conduct.
TTT is a new contributor. Be nice, and check out our Code of Conduct.
TTT is a new contributor. Be nice, and check out our Code of Conduct.
TTT is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333863%2fget-users-only-returns-one-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown