I’ve been like crazy looking for the way to get, in a PHP varialbe the ID of the author in the loop, in a sinle page.
I’,m sure that someone has done it and posted here, but i was unable to find it.
I need to show some code depenging on the author, and i wish i can solve it without any plugins (I have too many load in my server).
Thanks in advance.
it is allright to sort it out inside the loop, yes you can show the author_id inside the loop, so it will show the author_id as much as post count. like every post will have the author_id..
i am also trying to find out how to show author_id outside the loop..
You can always use http://guff.szub.net/2005/01/31/get-author-profile/ this plugin.
But what i was looking for is to get the autor ID inside the loop, but in a php variable.
i tried it but couldnt get it done with the get author profile..
i’ll give up i guess.. nobody helps..
yes i just tried ‘<?php get_the_author_ID(); ?>’ and it didnt work..
and also, when write ‘<?php get_the_author_ID(); ?>’ inside the loop it doesnt work.
if i write ‘<?php the_author_ID(); ?>’ inside the loop, it works
‘<?php the_author_ID(); ?>’ outside the loop, doesnt work.
get_the_author_IDwas to be used to assign the author ID to a variable inside the loop and was directed to marcrue.
abondanzieri–maybe Author_Templates has some information you can use.
What about this?
$thePostID = $wp_query->post->ID;
$postdata = get_postdata($thePostID);
$authorID = $postdata[‘Author ID’];
this code works! But only inside the loop.
What about if we’re looking to get that same ID outside of the loop?
I have a sidebar widget I’d need to have return the same ID both in and outside of the loop.
I had better luck with the following:
global $wp_query; $thePostID = $wp_query->post->ID; $postdata = get_post($thePostID, ARRAY_A); $authorID = $postdata['post_author'];
For out of the loop access, you’d just set $thePostID to the appropriate ID, depending on what post you’re getting the author for.
This also seems to work:
$alogin = get_query_var(‘author_name’);
$author = get_userdatabylogin($alogin);
- The topic ‘Get Author ID in PHP Variable when Single Page’ is closed to new replies.