get_posts – get all posts by author id

I’m a bit confused. If you want to get onlya element from the posts array you can get it like this:

  • reset($current_user_posts) – first post
  • end($current_user_posts) – lat post

But if you want to get just one post with the get_posts() you can use the posts_per_page argument to limit the results.

$args = array(
    'author'        =>  $current_user->ID,
    'orderby'       =>  'post_date',
    'order'         =>  'ASC',
    'posts_per_page' => 1
    );

More info about parameters you can get on WP Query Class Reference page (get_posts() takes same parameters as WP Query).

Leave a Comment