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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line