X

How to Display Today’s Posts Only in WordPress

Snippets by IsItWP

Are you looking for a way to display your WordPress post(s) but only from the current day? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display today’s posts only in WordPress.

Instructions:

All you have to do is add this code to your theme’s index.php file:

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

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress business themes for your website and how to create a contact form in WordPress.

Comments   Leave a Reply

  1. Thanx Man…..

  2. Ferhat Korkut July 11, 2013 at 5:54 am

    Thanks dude :))

  3. The above snippet shows all posts published at the same day of any month. (ex shows posts for sept 24, oct 24, nov 24 etc.)

  4. Thanks for this. Found it to be a great snippet. Could you extend this code to only display todays content from specific category?

  5. Tweets that mention Wordpress Display today’s posts only – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com January 28, 2011 at 3:07 pm

    […] This post was mentioned on Twitter by Michael Davis, WPSNIPP. WPSNIPP said: #wordpress Display today’s posts only http://bit.ly/fOIjxy #blog please RT 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!