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

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

$my_query = new WP_Query( array(
    'cat'=>1,
    'year'=>date('Y'),
    'monthnum'=>date('m'),
    'day'=>date('d'),
    'posts_per_page'=>-1 ) );

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

share|improve this answer
    
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 '11 at 22:12

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.