-1

I need to show the latest post by a specific author. For example, if 'test' author had two posts, one published on 1st January and the other on the 2nd January, I only want to show the 2nd Jan post. Thanks!

tomhuckle
  • 25
  • 3

1 Answers1

0

You could get the WP_Query ordered by date and search for the specific author requested by passing it as an arg.

$args = [
     'author'         => $author_id,
     'orbderby'       => 'post_date',
     'order'          => 'DESC',
     'posts_per_page' => 1,
 ];
 $latestPost = new WP_Query[$args]

And you don't even need to loop through it you could access it's field by just referencing it. $postContent = $latestPost->posts

McSoud
  • 1
  • 2