How to: Display today’s posts

If for some reason, you want to display only today’s posts on your blog homepage – or any other page – here’s a simple way to get theses posts and display it on your WordPress blog.

If you provide a lot of posts per days, it can be nice to display only today's posts on a separate page. To achieve this, we'll use the php date() function, and the WordPress query_posts() function.

Paste the following code where you want today's posts to be displayed:

$current_day = date('j');
query_posts('day='.$current_day);
if (have_posts()) :
     while (have_posts()) : the_post(); ?>
         // WordPress loop
     endwhile;
endif; ?>

7 Responses

Oct 14 2008 11:06

Nice hack, but only usable on blog which publish a lot of articles per day.

Nov 02 2008 09:36

add any screenshot brother
byme

Nov 02 2008 10:18

@byme: I don’t add screenshots, unless necessary. I don’t have much time and I must keep the standard “one day/one recipe” ;)

Oct 13 2009 16:12

This will actually give me all posts with the same day number…
If today’s Oct 13. Sept 13. posts are also returned.

Jan 13 2010 19:53

Works this code with wordpress 2.9.1?

Thanks for next useful recipe ;)
Dekoracje Tort

Sep 02 2010 06:18

Hi there

Thanks for this wonderful hack.

However, I’m having the same issue as Richard. It’s forcing my WordPress to display any posts made on the same day number.

Are there any fixes for this?

Thanks!
Harleigh

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required