Title: Get $author outside the loop
Last modified: August 19, 2016

---

# Get $author outside the loop

 *  Resolved [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * (@joshkadis)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/)
 * After showing the content of a post, I’d like to show excerpts of a few other
   posts by the same author. I’ve placed this query in single.php after The Loop:
 * `<?php $author = get_query_var('author'); query_posts("author=$author&cat=64&
   showposts=4"); ?>`
 * The cat and showposts parameters are working but author is not – it just shows
   4 posts in category 64 by any author). Incidentally, `<?php the_author(); ?>`
   works outside The Loop when placed just before the query.
 * Is there any other way to do this?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121937)
 * In your single.php
 * Put this in your loop:
 *     ```
       <?php
       $author_id=$post->post_author;
       ?>
       ```
   
 * Then this after your loop:
 *     ```
       <?php
       $args=array(
          'showposts' => 3,
          'author' => $author_id,
          'caller_get_posts'=>1
       );
       $posts=get_posts($args);
       if ($posts) {
         $curuser = get_userdata($author_id);
         $author_post_url=get_author_posts_url($curuser->ID, $curuser->nicename);
         echo 'User nicename: '.$curuser->user_nicename .', display Name: '. $curuser->display_name . ', link to author posts <a href="' . $author_post_url . '" title="' . sprintf( __( "Posts by %s" ), $curuser->user_nicename ) . '" ' . '>' . $curuser->user_nicename .'</a></p>';
         foreach($posts as $post) {
           setup_postdata($post); ?>
           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
         } // foreach($posts
       } // if ($posts
       ?>
       ```
   
 *  Thread Starter [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * (@joshkadis)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121960)
 * Thank you, that worked perfectly on single.php.
 * When I tried using it on other post templates (via this plugin: [http://wordpress.org/extend/plugins/templates-for-posts/](http://wordpress.org/extend/plugins/templates-for-posts/)),
   it doesnt’ show the nicename, display name, or link to author posts, and it shows
   three links to the current post instead of three other posts by the current post’s
   author.
 * Any idea why this would be the case?
 * Thank you.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121963)
 * Guess you’d might have to assign the correct value to the `$author_id` variable
   I had placed in the loop.
 *  Thread Starter [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * (@joshkadis)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121968)
 * I’m not sure I follow, sorry. Do you mean manually assign the value? I’m working
   on a multi-author blog so that wouldn’t be an ideal solution.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121970)
 * Not manually, but you may need to determine what variable does hold the post 
   author ID and assign it to the $author_id variable.
 *  Thread Starter [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * (@joshkadis)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121974)
 * Do you mean this?
 * ‘<?php
    $author_id=$post->[something other than post_author]; ?>’
 * Sorry, not the coding-est guy around. Thanks.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121977)
 * If it is a ‘standard’ loop, then $post->post_author should work but depends on
   what is holding your posts.
 * it could be:
    $author_id=$somethingelse->post_author
 *  Thread Starter [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * (@joshkadis)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121978)
 * Cool. Thanks again for your help.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Get $author outside the loop’ is closed to new replies.

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)
 * [meh_code](https://wordpress.org/support/topic-tag/meh_code/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [joshkadis](https://wordpress.org/support/users/joshkadis/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/get-author-outside-the-loop/#post-1121978)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
