WordPress is_new_day() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_new_day() is used inside The Loop. It returns 1 (true) when the current post was published on a different calendar day than the previous post. Otherwise it returns 0 (false).

It is used to print a date heading once for each day, instead of printing the same date above every post.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_new_day() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_new_day()True (1) for the first post of a new day.
the_date()Prints the date only once per day. It uses the same idea.
! is_new_day()True when the post is on the same day as the one before.

Posts are shown in date order, so posts of the same day appear together.

Full declaration
WordPress
is_new_day(): int

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
int1 if the current post is on a new day, otherwise 0. Both work in an if.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Date heading for each day

Print the date once for each group of posts.

WordPress
<?php while ( have_posts() ) : the_post(); ?>
  <?php if ( is_new_day() ) : ?>
    <h2><?php echo get_the_date(); ?></h2>
  <?php endif; ?>
  <h3><?php the_title(); ?></h3>
<?php endwhile; ?>

How It Works

  1. The loop runs once for each post.
  2. is_new_day() is true for Post A and Post C (new day).
  3. It is false for Post B, so no second heading is printed.

Example 2 — A divider between days

Print a line when a new day starts.

WordPress
<?php while ( have_posts() ) : the_post();
  if ( is_new_day() ) {
    echo '<hr>';
  }
  the_title( '<p>', '</p>' );
endwhile; ?>

How It Works

  1. A divider is printed before the first post of each day.
  2. Post B is on the same day as Post A, so it has no divider.
  3. Post C starts a new day, so a divider appears.

Example 3 — Count how many days

Count the groups of days on the page.

WordPress
<?php $days = 0;
while ( have_posts() ) : the_post();
  if ( is_new_day() ) {
    $days++;
  }
endwhile;
echo 'Days on this page: ' . $days; ?>

How It Works

  1. $days starts at 0.
  2. It goes up by 1 each time a new day starts.
  3. The total is printed after the loop.

Frequently Asked Questions

It returns 1 (true) or 0 (false), so you can use it directly in an if statement.
It returns the integer 1 or 0. Both work in an if statement.
No. It compares the current post with the previous post, so it needs the loop.
the_date() prints the date and already hides repeats. is_new_day() lets you do anything you like when a new day starts.

Next: is_page()

Check if the current page is a WordPress Page.

is_page() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful