How to Get Author Information Using Post ID in WordPress

It’s very simple but sometimes it’s crucial for our project. As well as we also need to know what is the best and easiest way to fetch post author information using post ID.

First and foremost, we need to find out the post ID. Inside the WordPress query loop, we can use get_the_ID() function to retrieve the post ID.

$post_id = get_the_ID();

Now we are going to use the get_post_field() WordPress function to retrieve the author ID. We can also fetch other information like this. Just need to change the post field name.

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

You might check the available post fileds names below in case you need to retrieve post_author, post_title etc –

ID
post_author
post_date
post_date_gmt
post_content
post_title
post_excerpt
post_status
comment_status
ping_status
post_password
post_name
to_ping
pinged
post_modified
post_modified_gmt
post_content_filtered
post_parent
guid
menu_order
post_type
post_mime_type
comment_count
filter

Post a Comment