WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get Author ID in PHP Variable when Single Page (13 posts)

  1. marcrue
    Member
    Posted 7 years ago #

    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.

  2. abondanzieri
    Member
    Posted 7 years ago #

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

  3. marcrue
    Member
    Posted 7 years ago #

    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.

  4. abondanzieri
    Member
    Posted 7 years ago #

    i tried it but couldnt get it done with the get author profile..

    i'll give up i guess.. nobody helps..

  5. MichaelH
    Member
    Posted 7 years ago #

    Did you try get_the_author_ID()?

  6. abondanzieri
    Member
    Posted 7 years ago #

    hello again,

    yes i just tried '<?php get_the_author_ID(); ?>' and it didnt work..

  7. abondanzieri
    Member
    Posted 7 years ago #

    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.

  8. MichaelH
    Member
    Posted 7 years ago #

    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.

  9. goxu
    Member
    Posted 7 years ago #

    What about this?

    global $wp_query;
    $thePostID = $wp_query->post->ID;
    $postdata = get_postdata($thePostID);
    $authorID = $postdata['Author ID'];

  10. suleiman
    Member
    Posted 7 years ago #

    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.

  11. bookchiq
    Member
    Posted 7 years ago #

    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.

  12. Magnus Melin
    Member
    Posted 7 years ago #

    This also seems to work:
    $alogin = get_query_var('author_name');
    $author = get_userdatabylogin($alogin);

  13. otravers
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic