dongren4758 2017-07-11 15:16 采纳率: 0%
浏览 206
已采纳

PHP:get_user_by(id)没有返回任何内容,user_id存在! WordPress的

Here is my code

$user_id = $_GET["user_id"];
$user = get_user_by('id',$user_id);
$balance = mycred_get_users_balance($user_id);
$user_info = get_userdata($user_id);
      $first_name = $user_info->first_name;
      $last_name = $user_info->last_name;

echo $first_name;
if ($balance > "0") {
        mycred_subtract( 'Check-in',$user_id, -1, 'Checked in.' );
        echo "Welcome " .$first_name." ".$last_name. "You are checked in.";

}
else{ echo "Welcome " .$first_name." ".$last_name;
echo "<br/>";
echo "You have a balance of " . $balance . ".";
    echo "<br/>";
    echo "Please purchase more credits at our website

I am trying to display the User first name and last name, this was working previously on my wordpress website, now the $user object is empty I'm quite sure because nothing is being echoed. I am able to parse the $user_id from the URL and echo it, but when I try to echo the $first_name, get nothing. I do get

Welcome You are checked in

Hence I know that the get_user_by is not working, the $user_id DOES exist in the database, I'm testing #1 which is my ID. I feel like it is something to do with a mobile optimization because we are scanning a QR code to redirect to this page and passing the user_id through the URL.

EDIT* I switched off JetPack smartphone optimization and got the functions working, except still no $first_name

Any ideas???

  • 写回答

1条回答 默认 最新

  • dsy1971 2017-07-11 20:35
    关注

    So it turns out I did not have a field stored as $first_name as I updated the registration form. I changed the $first_name to call for $user_nicename instead and it shows the users account display name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的