Unfortunately, wp_count_posts()
isn't going to get you there, it's only going to give you a flat number of all of that post_type (and whether it's readable or not).
The WP_Query
class seems a bit intimidating at first, but it should get you exactly what you need since it has a lot more granular control built in, namely the Date Parameters.
After initializing WP_Query
, you can use the found_posts
property (NOT post_count
!) to see how many posts it returned. Something like the following:
$week_query_args = array(
'posts_per_page' => -1, // No limit
'fields' => 'ids', // Reduce memory footprint
'post_type' => 'your_post_type',
'date_query' => array(
array( 'after' => '1 week ago' )
)
);
$week_query = new WP_Query( $week_query_args );
echo "We have {$week_query->found_posts} for the past 7 days";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…