文档中的示例应该可以正常工作。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' );