付费节点推荐
免费节点
节点使用教程
有时候我们需要获取当天或者本周或者其他时间段内的文章更新数量,这时候使用wordpress 自带的date_query就非常方便了。
获取今日更新数量
function get_today_post_count(){
$date_query = array(
array(
‘after’=>’1 day ago’
)
);$args = array(
‘post_type’ => ‘post’,
‘post_status’=>’publish’,
‘date_query’ => $date_query,
‘no_found_rows’ => true,
‘suppress_filters’ => true,
‘fields’=>’ids’,
‘posts_per_page’=>-1
);$query = new WP_Query( $args );
return $query->post_count;
}
获取本周更新数量
function get_week_post_count(){
$date_query = array(
array(
‘after’=>’1 week ago’
)
);$args = array(
‘post_type’ => ‘post’,
‘post_status’=>’publish’,
‘date_query’ => $date_query,
‘no_found_rows’ => true,
‘suppress_filters’ => true,
‘fields’=>’ids’,
‘posts_per_page’=>-1
);$query = new WP_Query( $args );
return $query->post_count;
}
可以看出,语义化的date_query实在是太方便了。
该文章由WP-AutoPost插件自动采集发布
原文地址:http://www.59iwp.com/1079.html
未经允许不得转载:Bcoder资源网 » WordPress 获取今日和本周更新文章数量
评论前必须登录!
登陆 注册