2014-02-07 5 views

답변

2

WP_Query class에 대한

덕분에이 작업을 수행 할 수 있습니다. 그냥 적절한 인수를 전달, 새 쿼리를 설정 :

<?php if ($my_date_query->have_posts()) : ?> 

    <!-- the loop --> 
    <?php while ($my_date_query->have_posts()) : $my_date_query->the_post(); ?> 
    <h2><?php the_title(); ?></h2> 
    <?php endwhile; ?> 
    <!-- end of the loop --> 

    <?php wp_reset_postdata(); ?> 

<?php else: ?> 
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 

날짜 매개 변수 섹션은 유형의 좋은 개요를 제공합니다 :

$args = array(
    'date_query' => array(
     // limit to between these dates 
     array(
      'after'  => '2014-02-01', 
      'before' => '2014-02-05', //remove this line if no upper limit 
      'inclusive' => true, 
      ), 
     // limit to posts before 17:10 (not tested) 
     array(
      'hour'  => 17, 
      'minute' => 10, 
      'compare' => '<=', 
      ), 
     // limit to posts after 08:30 
     array(
      'hour'  => 08, 
      'minute' => 30, 
      'compare' => '>=', 
      ), 
     ), 
    'posts_per_page' => -1, 
    ); 
$my_date_query = new WP_Query($args); 

그런 다음 당신은 그냥 instatiated 쿼리 객체를 사용하여 루프를 실행 작성 가능한 게시 검색어 수 : http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters

NBquery_posts을 사용하지 마십시오. the codex에서 :

query_posts (이) 지나치게 쿼리의 새 인스턴스로 교체하여 페이지의 주요 쿼리를 수정하는 단순하고 문제가있는 방법이다. 그것은 비효율적 인 (재 실행 SQL 쿼리)이며, 크게

+0

좋아 보인다 일부 상황에서 실패합니다, 당신은 내가 예를 들어, 지금까지이 시간부터 시간과 같은 필터, 을 넣을 수있는 방법을 알아? – Deimos

+0

시간 인수 추가, 시간 범위를 얻으려면 다른 수정 및 추가 – harryg

+0

게시물을 표시하지만 시간이 생각 나지 않는데 왜 오늘 예를 들어 2014-02-07에 대한 게시물을 표시하지 마십시오. 오늘 – Deimos

관련 문제