Hello.
I want to be able to get the post author's name or ID in single post view, but I couldn't find a working function in the WordPress codex yet.
get_the_author() can be used only inside The Loop and I want to get the information I need inside the <head> part of my site (before the Loop starts).
This seems to be more than meets the eye ... once you have the "post author's name or ID" what will you be doing with it?
For example, if this is style related, the body_class() function provides a class unique for each author.
I believe posts[0]->post_author would have the single post author ID
I will display custom JavaScript code based on the author.
I will try the solution that MichaelH provided and post. If I don't post, it means it works and I have forgot about this thread :D
It does work! Only instead of posts[0] it should be $posts[0].
This is the code that works for me:
$getid = $posts[0]->post_author;
if($getid == 5){
// Do something that is specific for user with ID 5
}
if($getid == 2){
// Do something for user with ID = 2
}
// And so on...
Good catch. Marking this resolved.