你已经拥有了全部帖子,所以为了在上周内获得全部帖子,最好在你的functions.php
文件:
function get_posts_count_from_last_week($post_type =\'post\') {
global $wpdb;
$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status=\'publish\' ".
"AND post_type= %s ".
"AND post_date> %s",
$post_type, date(\'Y-m-d H:i:s\', strtotime(\'-168 hours\'))
)
);
return $numposts;
}
然后在页脚中使用它。
<?php echo get_posts_count_from_last_week(); ?>
使用我们可以使用的类别
WP_Query:
$args = array(
\'cat\' => 4,
\'post_type\' => \'videos\'
);
$the_query = new WP_Query( $args );
echo $the_query->found_posts;