I am trying to produce user ID's from multiple specific usernames. The usernames are pulled from a profile field, and any number of usernames will be called. I want the user ID's from each of the users to be put into the 'include' of $args like 'include' => array( 1, 2),
. What am I doing wrong?
// Search these Usernames
$usernames = array( user1, user2 );
// Fetch the User IDs
$prof_ids = array();
foreach ($usernames as $prof_id) {
$user = get_user_by('user_login', $prof_id);
$prof_ids[] = $user->ID;
}
// WP_User_Query arguments
$args = array(
'include' => $prof_ids,
);
I tried printing each variable to see where I'm going wrong, and these are their outputs:
$usernames = Array
$prof_ids = Array
$prof_id = user2
$user =
$args = Array
I am trying to produce user ID's from multiple specific usernames. The usernames are pulled from a profile field, and any number of usernames will be called. I want the user ID's from each of the users to be put into the 'include' of $args like 'include' => array( 1, 2),
. What am I doing wrong?
// Search these Usernames
$usernames = array( user1, user2 );
// Fetch the User IDs
$prof_ids = array();
foreach ($usernames as $prof_id) {
$user = get_user_by('user_login', $prof_id);
$prof_ids[] = $user->ID;
}
// WP_User_Query arguments
$args = array(
'include' => $prof_ids,
);
I tried printing each variable to see where I'm going wrong, and these are their outputs:
$usernames = Array
$prof_ids = Array
$prof_id = user2
$user =
$args = Array
Share
Improve this question
asked Jun 13, 2019 at 18:14
MichaelMichael
2811 silver badge14 bronze badges
2
|
1 Answer
Reset to default 1Your call to get_user_by()
has a small hiccup in it. It needs to be login rather than user_login
// Search these Usernames
$usernames = array('user1', 'user2');
// Fetch the User IDs
$prof_ids = array();
foreach ($usernames as $prof_id) {
$user = get_user_by('login', $prof_id);
$prof_ids[] = $user->ID;
}
// WP_User_Query arguments
$args = array(
'include' => $prof_ids,
);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745404511a4626255.html
'include' => array( 1, 2),
, but it's not doing it as expected. In other words,$usernames = array( user1, user2 );
should produce'include' => array( 1, 2),
. My full code works fine if I type in'include' => array( 1, 2),
, but it does not work with this section of code. – Michael Commented Jun 13, 2019 at 18:25