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 want to get the number of posts for each category on a specific date. I think I can do the following: - get a list of categories - start loop ---create a query for each category and specific date loop and count posts - end first loop

Is there any easier way to do this?

I plan to put this in the php code widget. Note I have quite a few categories

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You would want to use something like this:

$query = new WP_Query( 'year=2013&monthnum=12&day=20&cat=5' ); 
// change cat=5 to the ID of the category you want to query from.
// change year to the year you want
// change monthnum to the month you want
// change day to the day you want

// start the loop
while( $query->have_posts() ) : $query->the_post();
     // do loop stuff
endwhile;

wp_reset_postdata();

Above says get all posts that has ID of 5 for category and the year of 2013 and month is 12 (December) and day is 20.

share|improve this answer
    
I was actually wondering if there is an easier way. Is there any performance cost to this? –  nilanjan Sep 4 '13 at 16:05
    
It is no different in performance than the regular loop. –  splashingpixels Sep 4 '13 at 16:07
add comment

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.