The get_the_author_ID() WordPress PHP function retrieves the ID of the author of the current post.
Usage
$author_id = get_the_author_ID();
Parameters
- None
More information
See WordPress Developer Resources: get_the_author_ID()
Examples
Display Author ID
Display the author ID of the current post.
$author_id = get_the_author_ID(); echo 'Author ID: ' . $author_id;
Get Author Email
Retrieve the email of the author of the current post using their ID.
$author_id = get_the_author_ID(); $author_email = get_the_author_meta('user_email', $author_id); echo 'Author Email: ' . $author_email;
Show Author Posts Link
Create a link to the author’s posts page using their ID.
$author_id = get_the_author_ID(); $author_posts_url = get_author_posts_url($author_id); echo '<a href="' . $author_posts_url . '">View All Posts by Author</a>';
Display Author Gravatar
Display the Gravatar of the author of the current post using their ID.
$author_id = get_the_author_ID(); $author_email = get_the_author_meta('user_email', $author_id); echo get_avatar($author_email);
Display Author Social Media Links
Display the author’s social media links (Twitter, Facebook, Instagram) using their ID.
$author_id = get_the_author_ID(); $twitter = get_the_author_meta('twitter', $author_id); $facebook = get_the_author_meta('facebook', $author_id); $instagram = get_the_author_meta('instagram', $author_id); echo '<ul>'; if ($twitter) { echo '<li><a href="' . $twitter . '">Twitter</a></li>'; } if ($facebook) { echo '<li><a href="' . $facebook . '">Facebook</a></li>'; } if ($instagram) { echo '<li><a href="' . $instagram . '">Instagram</a></li>'; } echo '</ul>';