【问题标题】:Wordpress get public user dataWordpress 获取公共用户数据
【发布时间】:2020-05-02 20:59:30
【问题描述】:

我试图在打开公共页面时获取有关用户的所有信息。

我使用这个函数来获取当前用户数据:

<?php global $current_user;
  wp_get_current_user();
   echo 'Username: ' . $current_user->user_login . "\n";
   echo 'User display name: ' . $current_user->display_name . "\n";
 ?>

但是,我需要的不是关于登录用户的信息,而是关于我正在访问该页面的用户的信息。 如何在他的公共页面中获取用户的信息并将其存储在变量中?

谢谢。

【问题讨论】:

  • 我很难理解您所说的“我正在访问该页面的用户”是什么意思?您是在询问有关未登录用户的详细信息吗?
  • 是的。关于另一个用户的个人资料并且该用户已登录。例如,当您访问 facebook 中某人的页面时
  • 你的意思是喜欢他们的author 页面吗?
  • 是的,我的意思是这个

标签: php wordpress authentication user-profile


【解决方案1】:

因此,您需要将其放入您的 archive.php 模板或 author.php 模板中。

有关详细信息,请参阅WordPress Template Hierarchy

// Check that it's an author archive with is_author()      
if (is_author()){
    $user = get_queried_object(); // If user will return object WP_User
    echo 'Username: ' . $user->user_login . "\n";
    echo 'User display name: ' . $user->display_name . "\n"; 
}

【讨论】:

    猜你喜欢
    • 2012-02-25
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    相关资源
    最近更新 更多