WordPress: show the date of the first post of an author

63 Views Asked by At

I'm looking for the PHP code to show the date of the first post of an author.

We want to echo the date on the authors page. Ideal would be german date format (e.g. 27.10.2023)

Do you have any ideas?

I found this code:

$user_id = 2;
$post = get_most_recent_post_of_user( $user_id );

if ( $post ) {
echo get_the_date( 'Y-m-d', $post );
}

but basically i want the opposite.

NOT the most recent post date, but the first post date of the current author.

1

There are 1 best solutions below

2
Vimal Usadadiya On BEST ANSWER

Try below code:

$args = array(
    'post_type' => 'post',
    'author' => $user_id,
    'order' => 'ASC',
);
$posts = get_posts($args);

echo get_the_time('Y-m-d', $posts[0]->ID);