I am trying to echo the number of posts for the current month from all categories but it isnt working.
<?php $month = date('m'); $year = date('Y'); $countposts = get_posts('post_type=post&year=' . $year . '&monthnum=' . $month . '&cat=3'); echo 'New posts ' . count($countposts); ?>
category 3 is a parent category and has many sub categories. No matter what I do, it returns the value 5. I have published 30 posts for this month to test it but it doesnt count them. :(
What Im I doing wrong?
Update I have tried the following query and returns the same outpout
<?php wp_reset_postdata(); $current_year = date('Y'); $current_month = date('m'); $args = array( 'cat' => 3, 'year' => $current_year, 'monthnum' => $current_month, 'post_status' => 'publish', 'post_type' => 'post' ); $number_posts = get_posts( $args ); echo 'New posts ' . count($number_posts); ?>