从数据库中取出帖子的优雅方法是使用wp_query. 它具有您需要的所有过滤器:
function wpse70323_count_user_posts_by_type( $userid, $post_type, $year, $month, $day ) {
$query = new WP_Query( array(
\'author\' => $userid,
\'post_type\' => $post_type,
\'date_query\' => array(
array(
\'year\' => $year,
\'month\' => $month,
\'day\' => $day,
),
),
\'posts_per_page\' => -1,
));
$count = $query->post_count;
return $count;
}
还可以根据需要返回日期范围。阅读上的文档
wp_query
为此。