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?
This should do the trick:
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:
That will allow you to preserve other query arguments that are supposed to be there.
I think you’ll need to set the month and year also(possibly), see the Time Parameters for WP_Query, parameters shown throughout that page also apply to
query_posts
.This is how I would do it.
You could also do it without modifying the theme. In WP Admin: Settings > Reading > Blog pages show at most: 1 posts