简体   繁体   中英

Wordpress Function That Will Display Post By Specific Author

I am trying to create a function that will display the 5 post made by a specific author.

Lets say the specific name of the Author is 'Nick' I don't know how to excute it.

I am using global variables for $post and $authordata.

Here's my snippet:

function display_post_via_specific_author() {

    global $authordata, $post;  //Declare Global Variables

    $authors_three_posts = get_posts( 
              array(
                'author' => $authordata->ID, 
                 'posts_per_page' => 3
                )
               );                          

    echo '<h5>Latest Posts by Sam</h5>';

    $output = '<ul>';
    foreach ( $authors_three_posts as $authors_post ) {
        $output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . get_the_title($authors_post->ID) . '</a></li>';

    }
    $output .= '</ul>';

    return $output;

}

I hope you can help me figure this out!

Thanks!

I know this might sound a little.. hm.. weird of an "answer",

but why don't you just link to his profile? It'll display recent articles by the author below him. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM