0

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

1 Answer 1

0

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.

2
  • I was actually wondering if there is an easier way. Is there any performance cost to this?
    – nilanjan
    Commented Sep 4, 2013 at 16:05
  • It is no different in performance than the regular loop.
    – user23654
    Commented Sep 4, 2013 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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