admin管理员组文章数量:1336632
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"
)
);
本文标签: meta querygetuser can39t read variable
版权声明:本文标题:meta query - get_user can't read variable 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742414495a2470446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论