How to get Author ID outside the loop

The simplest and most straightforward way to get the post author ID outside the loop, if you know the post ID, is to use the WordPress core function get_post_field().

$post_author_id = get_post_field( 'post_author', $post_id );

If you do not yet know the post ID of the page you are on, then since WP 3.1 the easiest thing to do is use the get_queried_object_id()(look for it in the list of Methods) function which works even outside the loop.

$post_id = get_queried_object_id();

If these do not work for you then please give a more detailed explanation of where you are trying to run your code and we can see if we can help further.

Leave a Comment