dongren4758
dongren4758
采纳率0%
2017-07-11 15:16 阅读 144
已采纳

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 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.

    点赞 评论 复制链接分享

相关推荐