<?php $my_query = new WP_Query("cat=1&day=''&posts_per_page=-1"); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

I'm trying to display all posts from a single day on my homepage, restricted by category. The code above is what I'm using, but I've tried a bunch of variations on listing the current day and can't seem to get it to display posts only from the current day. I'm sure I'm missing something completely obvious, but how do I get this working to restrict posts by date?

Although getting the homepage figured out is my first challenge, I also want to have my individual day archives set up in a similar way.

1 Answer 1


You'd have to specify day, month, and year to get today's posts:

$my_query = new WP_Query( array(
    'posts_per_page'=>-1 ) );

Leaving day blank just doesn't set that query var, so its not restricting your query at all.

  • Aah, I thought it would default to the current day. THANK YOU so much though, that did exactly what I was trying to get it to do.
    – user3903
    Mar 25, 2011 at 22:12

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.