WordPress 获取今日和本周更新文章数量

付费节点推荐

免费节点

节点使用教程

Clash 小火箭 v2ray节点购买

好用的梯子,海外网络,快速稳定

Google

有时候我们需要获取当天或者本周或者其他时间段内的文章更新数量,这时候使用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

bcoder

相关文章

评论(0)
游客的头像
表情
全部评论
最新