More posts from the current author

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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 ) . '" rel="nofollow noreferrer noopener">' . 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.

Method 2

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.

Method 3

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x