Something like this — this is untested, off the top of my head code
$args=array(
'order' => 'ASC',
'posts_per_page' => 1,
'orderby' => ID,
'ignore_sticky_posts' => 1,
);
$q = new WP_QUERY( $args ):
if ( $q -> have_posts() ) {
while( $q->have_posts() ) {
$q->the_post(); // at this point, you have the oldest post
}
}
wp_reset_postdata();
Hi,thanks:)An other question:i haven’t understood the logic behind the code.Can you explain it to me in words?
Get one post, sorted by ID, in ascending order. The post with the lowest ID should be the oldest.
Read the docs for wp_query:
https://codex.ww.wp.xz.cn/Class_Reference/WP_Query
I have understood but in what Way this code give us the post?In an array?
And why we have to use the While cycle to find the oldest post if we have requested it Early?