WordPress: get author info / user details from post id

Some times we needed to pull out the author data from a post id. It is very easy do it in wordpress.

It can be accomplished by the_author_meta() function or get_the_author_meta() function. You will need call this function in your theme or plugin, through a hook.

the_author_meta() –> Outputs the data, just like echo
get_the_author_meta() -> holds the value in value.

We can get the data like this :

 

$auth = get_post($post_ID); // gets author from post
$authid = $auth->post_author; // gets author id for the post
$user_email = get_the_author_meta('user_email',$authid); // retrieve user email
$user_firstname = get_the_author_meta('user_firstname',$authid); // retrieve firstname
$user_nickname = get_the_author_meta('nickname,$authid); // retrieve user nickname

The following list of user fields you can retrieve using this function.

  • 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

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *