【问题标题】:PHP: get_user_by(id) not returning anything, user_id exists! WordpressPHP:get_user_by(id) 不返回任何内容,user_id 存在! WordPress
【发布时间】:2017-07-11 15:16:27
【问题描述】:

这是我的代码

$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

我正在尝试显示用户的名字和姓氏,这以前在我的 wordpress 网站上工作,现在 $user 对象是空的,我很确定,因为没有任何内容被回显。 我能够从 URL 解析 $user_id 并回显它,但是当我尝试回显 $first_name 时,什么也得不到。 我明白了

Welcome You are checked in

因此我知道 get_user_by 不起作用,$user_id 确实存在于数据库中,我正在测试 #1 这是我的 ID。 我觉得这与移动优化有关,因为我们正在扫描二维码以重定向到此页面并通过 URL 传递 user_id。

EDIT* 我关闭了 JetPack 智能手机优化并让功能正常工作,但仍然没有 $first_name

有什么想法吗???

【问题讨论】:

  • 别猜了。调试。使用 var_dump 转储变量。

标签: php wordpress url


【解决方案1】:

事实证明,当我更新注册表单时,我没有存储为 $first_name 的字段。我将 $first_name 改为调用 $user_nicename,它会显示用户帐户的显示名称。

【讨论】:

    猜你喜欢
    • 2013-08-02
    • 2011-04-26
    • 2020-04-27
    • 2019-04-06
    • 2012-02-15
    • 2020-09-07
    • 2021-11-22
    相关资源
    最近更新 更多