函数原型
get_the_author_meta( string $field = ”, int|false $user_id = false ): string
函数描述
Retrieves the requested data of the author of the current post.
是否弃用
未弃用
函数参数
-
$field
string
Optional - The user field to retrieve.
Default:
'' -
$user_id
int|false
Optional - User ID.
Default:
false
函数返回值
string The author’s field from the current author’s DB object, otherwise an empty string.
函数位置
File: wp-includes/author-template.php.
函数源码
function get_the_author_meta( $field = '', $user_id = false ) {
$original_user_id = $user_id;
if ( ! $user_id ) {
global $authordata;
$user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
} else {
$authordata = get_userdata( $user_id );
}
if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ), true ) ) {
$field = 'user_' . $field;
}
$value = isset( $authordata->$field ) ? $authordata->$field : '';
/**
* Filters the value of the requested user metadata.
*
* The filter name is dynamic and depends on the $field parameter of the function.
*
* @since 2.8.0
* @since 4.3.0 The `$original_user_id` parameter was added.
*
* @param string $value The value of the metadata.
* @param int $user_id The user ID for the value.
* @param int|false $original_user_id The original user ID, as passed to the function.
*/
return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |

