admin管理员组文章数量:1023564
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 ?
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 ?
Share Improve this question asked Aug 1, 2018 at 8:29 topper1309topper1309 751 gold badge2 silver badges9 bronze badges 1 |1 Answer
Reset to default 3function 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
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 ?
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 ?
Share Improve this question asked Aug 1, 2018 at 8:29 topper1309topper1309 751 gold badge2 silver badges9 bronze badges 1-
You can use custom query $oldest_post_id = $wpdb->get_row("SELECT
id
FROM {$wpdb->posts} WHEREpost_type
= 'post' ANDpost_status
= 'publish' ORDER BYpost_date
ASC"); – Trilok Commented Aug 1, 2018 at 8:43
1 Answer
Reset to default 3function 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
本文标签: Quickest way to get last or oldest post dateWP Query
版权声明:本文标题:Quickest way to get last or oldest post date - WP Query 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745537146a2155012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
id
FROM {$wpdb->posts} WHEREpost_type
= 'post' ANDpost_status
= 'publish' ORDER BYpost_date
ASC"); – Trilok Commented Aug 1, 2018 at 8:43