How to Get Author ID in WordPress

To get the author ID, you can use the get_the_author_meta() function by passing the ID as an argument.

Below is an example of getting the author ID.

Get Author ID in WordPress


<?php

// get the author ID for current post
$author_id = get_the_author_meta('ID');
	
// display the author ID.
echo $author_id; 

?>

Get Author ID by Post ID in WordPress

To get the author ID by post ID, you can use the get_post_field() function, along with the post_author and post_id as parameters.

Below is an example of getting author id by post id.


<?php

global $post;
	
// will use get_post_field() with 'post_author' to get author id		
	
$author_id = get_post_field('post_author' , $post->ID);

	
// display the author ID.
echo $author_id; 

?>

Reference