我有一个基于usermeta字段查找user\\u id的小例程。。
$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
但如果我切换“meta\\u value”=>45455(使用已知的设备号),它将返回ID,没有问题。我已经尝试了$deviceid和“$deviceid”我缺少什么?
最合适的回答,由SO网友:Johnnyboy Gomez 整理而成
需要双引号
$WhoIsUser = get_users(
array(
\'meta_key\' => \'deviceid\',
\'meta_value\' => "$deviceid"
)
);