我想知道在WordPress中是否可以从自定义帖子类型中获取绝对最新帖子,但是第二个或第三个最新帖子。就像这个的任何其他代码一样:
<?php
$latest = new WP_Query(
array(
'post_type' => 'car',
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'modified',
'order' => 'ASC'
)
);
if($latest->have_posts()){
$modified_date = $latest->posts[0]->post_modified;
} ?>
答案 0 :(得分:2)
您可以使用偏移量跳过第一篇文章。
示例:
$second_latest = new WP_Query( array(
'post_type' => 'car',
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'modified',
'order' => 'DESC', // in OP you're using ASC which will get earliest not latest.
'offset' => 1, // skip over the first post.
'no_found_rows' => true, // optimize query since no pagination .needed.
) );
可以在WP_Query文档的分页部分找到偏移详细信息:http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters