WordPress – Retrieve author/user details from Post ID

Very often in your projects, you want to pull out the author data, given 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.

The below function, retreives user details like…

function author_details($post_ID)  {
$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

For full reference, please see: http://codex.wordpress.org/Function_Reference/the_author_meta

Similar Posts:

Balakrishnan Prabhu

Mr. Balakrishnan Prabhu is the founder of Corpocrat magazine. He is also the founder of Best Citizenships (BC), assisting wealthy individuals with with global citizenship and residency programs in Europe. His other interests are Linux, Machine learning, Wordpress, etc. You can contact him here

  • sharing the beautiful and informative, thank you ..

  • Andrew Brown

    $user_nickname = get_the_author_meta(‘nickname,$authid); // retrieve user nickname
    missing a ‘ in there