Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On a multi author WordPress blog I need to show a list with more posts from the current author. The list is inside the Loop, so I can use <?php the_author_meta('first_name'); ?> <?php the_author_meta('last_name'); ?> and <?php the_author_meta('description'); ?>, but how to retrieve the user's posts?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

This will retrieve the posts of current author when used in the loop.

Put the following in your theme functions.php:

function my_get_display_author_posts() {
    global $authordata, $post;

    $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ) ) );

    $output = '<ul>';
    foreach ( $authors_posts as $authors_post ) {
        $output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
    }
    $output .= '</ul>';

    return $output;
}

And add echo my_get_display_author_posts(); in your template file, within the loop where you want the posts displayed.

share|improve this answer
    
thank you! That was the snippet I've searched. –  Dimitar Jan 3 '11 at 19:06
1  
Good answer and for users with performance in mind, you could wrap that functionality into an Ajax callback for fetching those posts on demand. –  t31os Jan 4 '11 at 16:54
    
How would you use this outside of the loop? –  user3231 Feb 16 '11 at 23:06

Use get_posts() with Author Parameters (they are in query_posts() documentation, but these two function mostly takes same arguments).

Do not use query_posts() for this, it's meant for modifying main page's Loop.

share|improve this answer
    
I tried but without success, because this retrieves the posts from specific author. My list should show on a page with posts from many authors and I would like to show "more from this author" after/around each post of every author. –  Dimitar Jan 1 '11 at 13:29
    
@Dimitar well the point kinda is retrieving post from specific author... If you need it several times - just retrieve several sets of post, providing different authors in parameters. –  Rarst Jan 1 '11 at 19:03

I think you can use the wordpress query_posts function for this. Take a look at http://codex.wordpress.org/Function_Reference/query_posts . This might not be enough to do what you need, but should get you started looking around the function reference.

share|improve this answer
    
query_posts() shouldn't be used for anything other than modifying main Loop. For everything else there are get_posts() or WP_Query object. –  Rarst Dec 31 '10 at 9:51
    
I thought in his question he said he was inside the loop. –  benstraw Jan 2 '11 at 5:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.