반응형
Get_posts는 X일 이내 - Wordpress
워드프레스 사이트에서는 다음 get_posts 코드를 사용합니다.
get_posts(
array (
'numberposts' => 5,
'orderby'=>'comment_count',
'order'=>'DESC',
'post_type' => array ( 'post' )
)
게시물이 10일을 넘지 않도록 필터링하려면 어떻게 해야 합니까?따라서 지난 10일 동안의 게시물만 나열해야 합니다.
3.7부터는 date_module https://developer.wordpress.org/reference/classes/wp_query/ #date-parameters를 사용할 수 있습니다.
예를 들어 다음과 같습니다.
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
'orderby' => 'comment_count',
'order' => 'DESC',
'date_query' => array(
'after' => date('Y-m-d', strtotime('-10 days'))
)
);
$posts = get_posts($args);
의사 선생님 예제는 잘 될 겁니다.get_posts()는 실제 요구를 하기 위해 백그라운드에서 WP_Query()를 사용합니다.이 경우 수정된 예는 다음과 같습니다.
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
// posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-10 days')) . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = get_posts(array (
'numberposts' => 5,
'orderby'=>'comment_count',
'order'=>'DESC',
'post_type' => array ( 'post' )
));
remove_filter( 'posts_where', 'filter_where' );
언급URL : https://stackoverflow.com/questions/16994364/get-posts-no-older-than-x-days-wordpress
반응형
'programing' 카테고리의 다른 글
| _reactDom2.default.render는 함수가 아닙니다. (0) | 2023.04.04 |
|---|---|
| JOIN의 ON 절에서 참조되는 테이블의 순서가 중요합니까? (0) | 2023.04.04 |
| 오라클 SQL 테이블의 날짜 업데이트 (0) | 2023.04.04 |
| $rootScope를 사용하는 이유는 무엇입니까?AngularJS로 $broadcast? (0) | 2023.04.04 |
| @Spring Boot Test에서의 값 "플레이스 홀더를 해결할 수 없습니다" (0) | 2023.04.04 |