Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
wp_reset_postdata();

Is there a lighter way to obtain the same?

share|improve this question

1 Answer 1

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

 
discard

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.