0

I know how to get the last or oldest post data using following code

$posts = get_posts(array(
  'post_type' => 'post',
  'order_by' => 'publish_date',
  'order' => 'ASC'
));

And then I will get the date from the first array itself, but is there any quickest way to get that ?

  • You can use custom query $oldest_post_id = $wpdb->get_row("SELECT id FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC"); – Trilok Aug 1 '18 at 8:43
1
function is_first() {
    global $post;
    $loop = get_posts( 'numberposts=1&order=ASC' );
    $first = $loop[0]->ID; 
    return ( $post->ID == $first ) ? true : false;
} 

you can use this too

  • This also works, but for me this was the best one $oldest_post_id = $wpdb->get_row("SELECT post_date FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC"); – topper1309 Aug 1 '18 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.