meta query - get_user can't read variable

I have this little routine to find the user_id based on a usermeta field.. $scaleData = json_decode($reading, TRUE);$de

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
Add a comment  | 

1 Answer 1

Reset to default 0

Needs double quotes

$WhoIsUser = get_users(
  array(
   'meta_key' => 'deviceid',
   'meta_value' => "$deviceid"
 )
);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742414495a4439471.html

相关推荐

  • meta query - get_user can't read variable

    I have this little routine to find the user_id based on a usermeta field.. $scaleData = json_decode($reading, TRUE);$de

    11小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信