Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top