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.
Related Posts:
- Display all authors and their only one latest post
- Display Authors in a grid loop
- Cannot retieve the_content() and the_author() – both returning empty strings
- Get author_id in wordpress
- Display Post Author Link above the loop
- How can I display other user avatars on an author profile page?
- Can’t grab author info outside of the loop
- Saving return value from the_author_posts_link()
- Display more than 10 posts on author.php file
- How to add a byline to all the pages?
- Use Author Ids or Names to echo different output inside loop
- List ALL posts by author on author archive
- Displaying posts limit: can’t get pagination to display [duplicate]
- Exclude Authors based off date of last post
- WordPress loop: Display if posts exist
- How to get the role id from the role name?
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- How to hook into container
- Is wp_reset_postdata() redundant after the main loop?
- Exclude first post (sticky or not) from the loop using query_posts()
- How to add a specific div element to the first post in a row?
- While loop with bootstrap [closed]
- Need to add class to first element in a foreach loop
- Scrolling Posts with Ajax
- Sort posts by first letter in the title, not by first number
- How to create a multidimensional array with multiple loops
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- What PHP Needed to Make One Loop with Multiple Styling?
- Simple foreach loop help needed in wordpress “the loop”
- Get paged outside of loop?
- How to create custom popup in shop page on every loop products?
- Show scheduled posts in loop (but don’t link to them)?
- How to get a count of all posts in foreach loop and split into fourths
- Getting posts link in WordPress
- Loop through an array inside a class using foreach [closed]
- using wp_get_attachment_image_src in foreach loop
- Grabbed Post ID under WP loop, but still couldn’t Print Post title
- How to loop through yoast primary categories? [closed]
- How to separate posts loop in to two columns? [duplicate]
- WordPress get post thumbnail url
- query_posts clarification needed
- Accessing Post ID Within Loop
- Blank content php code not parsing advanced custom fields gallery add-on [closed]
- Three Column Loop
- Split loop into columns
- get_posts() forcing ignore sticky posts on main loop
- display post tags on single.php inside loop
- Custom content before post content
- linking to post outside the loop
- Can’t get the previous and next posts permalink
- Adding first and last classes to three column layout in Bones boilerplate
- make diffrent template on last six post published
- Modifying a Loop to Show More
- Determine if ID is page or post and query the ID
- “the_excerpt” in loop just keeps repeating first post?
- wpdb inside foreach loop only returns first result – 2 other similar cases found [closed]
- Using jQuery .after inside loop
- How to check all items in a loop have post thumbnail?
- Add 2 values to post__not_in
- Display posts differently depending on which author wrote it
- Page Navigation Outside the Loop
- How to make the following loop break/stop when it reaches 2 posts (custom post types called Topics)?
- How to loop specific Category menu from archive page?
- How to display post tag on each post? [closed]
- How can I pass additional params to a shortcode while in a loop?
- ACF: display custom filed of CPT into the loop
- Solved – Inserting content inside the WordPress loop
- Add Search and Filter functionality to custom loop
- How to add “NEW” badge on latest posts or published 3 days interval
- Add all category as classes in foreach loop
- Exclude posts from loop by term
- How to avoid appending “null” in Ajax?
- Alternative layout the loop
- Why loop renders only last metabox from array? [closed]
- Show posts by tags excluding current post
- Adding options to loop
- Issue with WP_Query (need a array of selected ID’s)
- Structure and Display Content from Multiple Pages on Single Page
- Creating a archive for taxonomy terms, not the term results
- Featured posts and the loop
- How to fix pagination for custom loops?
- Thumbnail of the latest posts page
- Display latest posts using WP Loop with different size divs
- Combining external feed into post loop
- Get last 5 days with posts
- Is there a way to target only images within the loop?
- Code to check amount of blog posts and add css
- Loop to get current parent page “content” and his children content
- Add Div IDs dynamically to CSS
- Show last post from multiple categories using wp_list_categories
- Load featured article once in a loop
- Please help me to win the battle with 2 column loop by category
- Display content from “About Us” page on the Home Page
- How to use add_action(“wpcf7_before_send_mail” outside wp loop?
- repeating posts on 2nd page to posts
- Limitless amount of posts in custom archive page
- Query parsing only author ids
- Two loops in CPT archive page, exclude posts from main query
- How i can display all posts order by years
- How to make FSE’s query loop to order by comments number?