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 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
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


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. – user23654 Sep 4 '13 at 16:07

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.