• Resolved marcrue

    (@marcrue)


    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • 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..

    Thread Starter marcrue

    (@marcrue)

    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..

    Did you try get_the_author_ID()?

    hello again,

    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.

    Sorry, get_the_author_ID was 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?

    global $wp_query;
    $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 method posted by magnus78 worked for me. Is there any way to change it to fetch the author’s first and last name instead of their IDs?

    I’ve tried the methods listed in the help file but couldn’t get them to work (in WordPress 2.1).

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Get Author ID in PHP Variable when Single Page’ is closed to new replies.