最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

meta query - get_user can't read variable

programmeradmin0浏览0评论

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"
 )
);
发布评论

评论列表(0)

  1. 暂无评论