Wordpress - get post author id outside loop
The easiest way would be using get_post_field()
:
$post_author_id = get_post_field( 'post_author', $post_id );
For more details on this issue: have a look at this StackOverflow answer.
You can use the following:
/**
* Gets the author of the specified post. Can also be used inside the loop
* to get the ID of the author of the current post, by not passing a post ID.
* Outside the loop you must pass a post ID.
*
* @param int $post_id ID of post
* @return int ID of post author
*/
function wpse119881_get_author( $post_id = 0 ){
$post = get_post( $post_id );
return $post->post_author;
}