万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
テンプレートタグ/the author meta
目次
解説
the_author_meta テンプレートタグを使えば、あるユーザーが持つメタデータから好きなものを表示することができます。このタグをループの中で使った場合、ユーザー ID を指定する必要はなく、表示されるデータは現在の投稿の作成者のものになります。ループの外で使う場合、ユーザー ID を指定する必要があります。
指定したメタデータが存在しなければ、何も表示されません。
注:この情報を PHP で使うために戻り値として使用したい(表示しない)場合は、get_the_author_meta() を使ってください。
使用法
<?php the_author_meta( $field, $userID ); ?>
パラメータ
- $field
- (文字列) 表示したいデータのフィールド名。有効な値は以下の通りです。
- user_login
- user_pass
- user_nicename
- user_email
- user_url
- user_registered
- user_activation_key
- user_status
- display_name
- nickname
- first_name
- last_name
- description
- jabber
- aim
- yim
- user_level
- user_firstname
- user_lastname
- user_description
- rich_editing
- comment_shortcuts
- admin_color
- plugins_per_page
- plugins_last_view
- ID
- $userID
- (整数) (オプション) これが指定されると、この ID を持つユーザーの情報が表示されます。
- 初期値: false
戻り値
このテンプレートタグは値を返しません。
例
投稿作成者の AIM アカウント名を表示する
投稿の作成者の AIM (AOL Instant Messenger アカウント) フィールドを表示します。
<p>この著者の AIM アカウントは <?php the_author_meta( 'aim' ); ?> です。</p>
特定のユーザーのメールアドレスを表示する
ID が 25 であるユーザーのメールアドレスを表示します。
<p>ID 25 のユーザーのアドレスは <?php the_author_meta( 'user_email', 25 ); ?> です。</p>
高度な使い方
プラグインを使ってユーザー登録時や管理画面から wp_usermeta テーブル(wp_ はデータベース接頭辞)に新しい値を追加することができます。以下は、あるプラグインが meta_key を "twitter" と設定し、その meta_value が "wordpress" となっている場合の例です。
<p>投稿者の Twitter ID: <?php the_author_meta( 'twitter' ); ?></p>
と書くと、次のように表示されます。
変更履歴
- 2.8 : 新規テンプレートタグ
ソースファイル
the_author_meta() は wp-includes/author-template.php
内にあります。
関連情報
作成者タグ: the_author(), get_the_author(), the_author_link(), get_the_author_link(), the_author_meta(), get_the_author_meta(), the_author_posts(), get_the_author_posts(), the_author_posts_link(), get_author_posts_url(), get_the_modified_author(), the_modified_author(), wp_dropdown_users(), wp_list_authors()
最新英語版: WordPress Codex » Template Tags/the_author_meta (最新版との差分)