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!