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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀