I have this little routine to find the user_id based on a usermeta field..
$scaleData = json_decode($reading, TRUE);
$deviceid = $scaleData["imei"];
echo $deviceid; // check to confirm is working. Yup
$WhoIsUser = get_users(
array(
'meta_key' => 'deviceid',
'meta_value' => '$deviceid'
)
);
$CurrentUser = $WhoIsUser[0]->ID;
echo $CurrentUser; //returns nothing
But if I switch 'meta_value' => 45455 (iow a known device number) it returns the ID no problem. I've tried both $deviceid and '$deviceid' What am I missing?
I have this little routine to find the user_id based on a usermeta field..
$scaleData = json_decode($reading, TRUE);
$deviceid = $scaleData["imei"];
echo $deviceid; // check to confirm is working. Yup
$WhoIsUser = get_users(
array(
'meta_key' => 'deviceid',
'meta_value' => '$deviceid'
)
);
$CurrentUser = $WhoIsUser[0]->ID;
echo $CurrentUser; //returns nothing
But if I switch 'meta_value' => 45455 (iow a known device number) it returns the ID no problem. I've tried both $deviceid and '$deviceid' What am I missing?
Share Improve this question asked May 20, 2020 at 22:41 Johnnyboy GomezJohnnyboy Gomez 333 bronze badges 2- I think you should remore the quotes around $deviceid, that should be the reason why it is not getting a value. With the quotes he is not loading the value of the variable, but just the string. But you said you already tried that... have you tried outputting the value to see if the Id is correctly saved in the variable you use as meta_value? – rank Commented May 20, 2020 at 22:53
- Got it! I needed to use "double-quotes". Such a simple mistake and hours lost! Thx your comment got me thinking on the right path. – Johnnyboy Gomez Commented May 20, 2020 at 23:24
1 Answer
Reset to default 0Needs double quotes
$WhoIsUser = get_users(
array(
'meta_key' => 'deviceid',
'meta_value' => "$deviceid"
)
);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742414495a4439471.html
评论列表(0条)