This question already has an answer here:

<?php if ( have_posts() ) : ?>
<?php
// Start the loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
else :
get_template_part( 'content', 'none' );
endif;
?>

A simple loop her eon my index page. I am using the No Future Posts plugin to publish posts with dates in the future but the most relevant ones are today.

I have been doing a ton of cutting and pasting code from around the net trying to find a way to get just todays posts to show but nothing is sticking. I'm sure I need to check for todays date then put it into the loop but I have no idea how to do that, I know very little php, I usually just copy and paste other peoples code.

If any of the experts on here could maybe point me in the right direction it would be appreciated.!

marked as duplicate by Howdy_McGee, kaiser May 29 '16 at 14:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I read through that and the people on there seem confused what theyre talking about so I have no chance – Martin Lyle May 18 '16 at 2:01
  • I am trying, I'm also starting from scratch. Where do I put the code under the section labelled "Returns posts for today:" ? – Martin Lyle May 18 '16 at 2:26
  • Always file edits to your question when try something (and fail). Describe what you tried and what exactly failed. "Where do I put the code" probably is not the best question to ask on a development site. – kaiser May 29 '16 at 14:32
up vote 6 down vote accepted

If you just want posts from today, it's super easy and right in the WP codex:

<?php
$today = getdate();
$args = array(
    'date_query' => array(
        array(
            'year'  => $today['year'],
            'month' => $today['mon'],
            'day'   => $today['mday'],
        ),
    ),
);
$custom_query = new WP_Query( $args );
?>

<?php if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); ?>

  <?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; endif; // end of custom loop ?>
<?php wp_reset_postdata(); ?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.