WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to get just the number of posts published in one particular day. I'm using this code, but this retrieve lot of code:

$day = date('Ymd');
$query01 = array('numberposts' => -1, 'post_type' => array('post', 'video', 'image', 'review'), 'm' => $day);
$mypost = get_posts($query01);
$counter = count($mypost);

Is there a lighter way to obtain the same?

share|improve this question
up vote 2 down vote accepted

$wp_query->found_posts can be used to get the number of posts. But here are arguments you can use to optimize the query and avoid useless SQL retrievals:

cache_results' => false, // Turns off post caching
'no_found_rows' => true, // To optimize when pagination is not required
'fields' => 'ids'  // To only retrieve IDs information, nothing else (avoid collecting all useless post data)

If you have more optimizing tips for simple queries, I would be happy to hear about them

share|improve this answer
Good point. Thank you. – Francesco Dec 13 '12 at 23:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.