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
'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.