You can pass the post’s author as an argument to get_the_author_meta
:
get_the_author_meta('ID', $post->post_author);
The second argument is the user’s ID. This is stored in the post object in your loop, which you can access it by using $post->post_author
.
Reason
The reason behind the current code of yours that isn’t working is this piece of code that is included in the get_the_author_meta()
:
if ( ! $user_id ) {
global $authordata;
$user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
} else {
$authordata = get_userdata( $user_id );
}
If you set the second argument to true ( which is the $user_id
), it will trigger the else
, and by triggering the else you are passing a true
to the get_userdata()
, which will obviously won’t work.
Take a look at this page of code reference for more details.