0

任何人都知道如何使用 wordpress 查询在特定类别中计算每天的更新帖子(例如:在这一天/日期)?

非常感谢。

4

1 回答 1

1

我不知道我是否完全理解您的问题,您是否想要统计在特定日期/日期发布的特定类别的帖子?

在这种情况下,您只需创建一个WP_Query实例并传入您想要查看的时间参数类别。

就像是,

<?php
$today = getdate();
$args = array('year' => $today["year"], 'monthnum' => $today["mon"], 'day' => $today["mday"], 'category_name' => 'Uncategorized');
$search = new WP_Query($args);
$count = $search->found_posts;
?>

如果您想根据修改日期返回帖子(您声明每天更新帖子,我不明白),那么您需要添加一个“posts_where”过滤器而不是 args 的时间参数。

有关示例代码和使用说明,请参见上面的时间参数链接 - 但在稍微修改其中一个示例时,您可以创建类似这样的内容。

// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
$where .= " AND post_modified >= '2010-03-01' AND post_modified < '2010-03-16'";
return $where;
}

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
于 2012-09-08T17:20:01.213 回答