2015-01-16 4 views
1

WordPress에서 사용자 정의 게시 유형에서 절대 최신 게시물을받지 못하고 2 번째 또는 3 번째 최신 게시물을 가져올 수 있는지 궁금합니다. 이 코드의 다른 코드와 마찬가지로 :두 번째 최신 사용자 정의 게시 유형 얻기

<?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; 
} ?> 

답변

2

오프셋을 사용하면 첫 번째 게시물을 건너 뛸 수 있습니다.

예 : http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

+0

아주 좋은이, perfectliy 작동합니다

$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의 문서의 페이지 매김 섹션에서 찾을 수 있습니다 오프셋! – Irene