get_the_author_meta

Retrieve the requested data of the author of the current post.

Description

(string) get_the_author_meta( (string) $field = '', (bool) $user_id = false ); 

Returns (string)

The author's field from the current author's DB object.

Parameters (2)

0. $field — Optional. (string) => ''
Selects the field of the users record.
1. $user_id — Optional. (bool) => false
User ID.

Usage

  1. if ( !function_exists( 'get_the_author_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/author-template.php'; 
  3.  
  4. // selects the field of the users record. 
  5. $field = ''; 
  6.  
  7. // Optional. User ID. 
  8. $user_id = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_the_author_meta($field, $user_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/author-template.php  
  1. function get_the_author_meta( $field = '', $user_id = false ) { 
  2. $original_user_id = $user_id; 
  3.  
  4. if ( ! $user_id ) { 
  5. global $authordata; 
  6. $user_id = isset( $authordata->ID ) ? $authordata->ID : 0; 
  7. } else { 
  8. $authordata = get_userdata( $user_id ); 
  9.  
  10. if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) 
  11. $field = 'user_' . $field; 
  12.  
  13. $value = isset( $authordata->$field ) ? $authordata->$field : ''; 
  14.  
  15. /** 
  16. * Filters the value of the requested user metadata. 
  17. * The filter name is dynamic and depends on the $field parameter of the function. 
  18. * @since 2.8.0 
  19. * @since 4.3.0 The `$original_user_id` parameter was added. 
  20. * @param string $value The value of the metadata. 
  21. * @param int $user_id The user ID for the value. 
  22. * @param int|bool $original_user_id The original user ID, as passed to the function. 
  23. */ 
  24. return apply_filters( 'get_the_author_' . $field, $value, $user_id, $original_user_id );