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() 的用法完全一樣,只是一個是返回資料,一個是直接列印資料。