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!
Asked
Active
Viewed 23 times
1 Answers
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
-
You could also probably achieve such result using the `get_posts()` – McSoud Mar 07 '23 at 13:22