2012-09-07 21 views

回答

1

我不知道我是否完全理解您的問題,是否需要計算特定日期/日期上發佈的特定類別的帖子數?

在這種情況下,您可以創建一個WP_Query的實例並傳入time parameterscategories您希望您查看。

喜歡的東西,

<?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 '過濾而不是參數的時間參數。

請參閱上面的時間參數鏈接以獲取示例代碼以及使用此示例的解釋 - 但稍微修改其中一個示例,您可以創建類似的內容。

// 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'); 
+0

感謝您的幫助,這就是我在尋找'...但我解決了我的代碼。 –

相關問題