How to show only today’s post?

I want to show only today’s or current date post in my blog.
Here is my code but it’s not working.

<?php   
$day = date('j');   
query_posts('day='.$day);   
if (have_posts()) :
while (have_posts()) : the_post();  
?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="view: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="storycontent"><?php the_content(); ?></div>
<?php endwhile; ?>
<?php endif; ?>

How to solve this?

Related posts

Leave a Reply

4 comments

  1. This should do the trick:

    <?php
    $day = date('Ymd');
    query_posts("m=$day");
    

    The query arg 'm' for WordPress will be interpreted as a year if it is four characters long, a month if 6, and a date if 8.

    EDIT

    You should probably add in the original query string just in case you’re writing enough to need things like pagination:

    <?php
    global $query_string;
    $query_string = empty($query_string) ? 'm=' : $query_string . '&m=';
    $query_string .= date('Ymd');
    query_posts( $query_string );
    

    That will allow you to preserve other query arguments that are supposed to be there.

  2. This is how I would do it.

    <?php
    $today = getdate();
    
    query_posts( array(
        'year' => $today["year"],
        'monthnum' => $today["mon"],
        'day' => $today["mday"]
    ) ); 
    
    // Do your loop... thingy.