2017-12-26 7 views
0

수정 된 날짜의 모든 WordPress 게시물을 가져 오는 다음 코드를 시도했지만 수정 된 날짜의 게시물을 가져올 수 없습니다. 다음 코드를 사용하면 데이터가 post_date이 아닌 post_modified이됩니다. 게시물이 25-12-2017modified date이고 그 post date은 23-12-2017입니다. 게시물을 수정 한 날짜별로 데이터를 가져오고 싶습니다. 수정 된 날짜로 Wordpress 목록 게시물

감사합니다

첫 번째 코드 :

<?php 
$args = array(
    'posts_per_page' => $Limit, 
    'post_type' => 'post', 
    'orderby' => 'modified', 
    'offset' => ($Page - 1) * $Limit, 
    'year'=>date('Y'), 
    'monthnum'=>date('m'), 
    'day'=> 25, 
    'order'=> 'DESC', 
); 
?> 

두 번째 코드 : 기본 워드 프레스에 의해

<?php 
$args = array(
    'posts_per_page' => $Limit, 
    'post_type' => 'post', 
    'orderby' => 'modified', 
    'offset' => ($Page - 1) * $Limit, 
    'date_query' => array(
     array(
      'after'  => "December 24, 2017",    
     ), 
    ), 
); 
?> 

답변

1

내가 생각하지 않는이 기능을 가지고 있지만, 이 목표를 달성 할 수있는 필터. 당신의 functions.php 파일

function scopePostModifiedDate($sql) 
{ 
    global $wpdb; 
    $sql .= $wpdb->prepare(" AND DATE($wpdb->posts.post_modified) >= %s ", '2017-12-25'); 
    return $sql; 
} 

쓰기이 그리고이 코드는 당신이 필요할 때마다 : 여기

은 샘플 코드입니다

add_filter('posts_where', 'scopePostModifiedDate'); 

$args = array(
    'posts_per_page' => $Limit, 
    'post_type' => 'post', 
    'orderby' => 'modified', 
    'offset' => ($Page - 1) * $Limit, 
// 'date_query' => array(
//  array(
//   'after'  => "December 24, 2017",    
//  ), 
// ), 
); 
$custom_query = new WP_Query($args); 
remove_filter('posts_where', 'scopePostModifiedDate'); 
//print_r($custom_query->request); //print SQL query 

에 refrence :