get_the_author_meta() 函數用來獲取網站用户的信息,如果在循環中則不需要指定用户的 ID,直接調用當前文章的作者的信息,否則必須得指定需要獲取的用户的 ID

用法

1

get_the_author_meta($field,$user_id);

參數

$field

(字符串)(可選) 要返回的數據項,可選值:

  • user_login
  • user_pass
  • user_nicename
  • user_email
  • user_url
  • user_registered
  • user_activation_key
  • user_status
  • roles
  • display_name
  • nickname
  • first_name
  • last_name
  • description
  • jabber
  • aim
  • yim
  • user_level
  • user_firstname
  • user_lastname
  • rich_editing
  • comment_shortcuts
  • admin_color
  • plugins_per_page
  • plugins_last_view
  • ID

默認值:None

$user_id

(整數)(可選) 需要返回的數據的用户 ID 。如果在循環裏可以不指定,會自動指定為當前文章的作者。

默認值:None

例子

獲取用户郵箱:

1

$user_email=get_the_author_meta('user_email');

獲取指定 ID 用户的顯示名稱:

1

get_the_author_meta('display_name',25);

其它

該函數位於:wp-includes/author-template.php

還有一個 the_author_meta() 函數,和 get_the_author_meta() 的用法完全一樣,只是一個是返回數據,一個是直接打印數據。