I have some doubts about how work the WordPress the_date() functions definied into general-template.php

In a page I show the posts archive using this code snippet into a loop:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>                              


        <h3 class="entry-title">
                <a href="<?php the_permalink(); ?>" 
                   title="<?php printf(__('Permalink to %s', 'your-theme'), the_title_attribute('echo=0')); ?>"
                   rel="bookmark"><?php the_date("d/m/Y");  echo " - "; the_title(); ?>



</article>  <!-- #post-<?php the_ID(); ?> -->

The problem is that for some posts the the_date() function give me the date of the post and for other posts not.

I attach a screnshot of what I obtain:

enter image description here

As you can see some posts are shown as something as: DATE - POST TITLE but some other posts are shown as POST TITLE without the date before the post title.

This seems to me very strange because all the posts have a publishing date.

So I tried to use the debugger and see what happens when the the_date() function have this code:

function the_date( $d = '', $before = '', $after = '', $echo = true ) {
    global $currentday, $previousday;

    if ( $currentday != $previousday ) {
        $the_date = $before . get_the_date( $d ) . $after;
        $previousday = $currentday;

         * Filter the date a post was published for display.
         * @since 0.71
         * @param string $the_date The formatted date string.
         * @param string $d        PHP date format. Defaults to 'date_format' option
         *                         if not specified.
         * @param string $before   HTML output before the date.
         * @param string $after    HTML output after the date.
        $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );

        if ( $echo )
            echo $the_date;
            return $the_date;

    return null;

and it contains this conditional statment:

if ( $currentday != $previousday ) {

and I see that for some posts the value of $currentday and of $previousday is the same so the function return null

Also reading the funcion documentation I can find:

 * Display or Retrieve the date the current post was written (once per date)
 * Will only output the date if the current post's date is different from the
 * previous one output.
 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
 * function is called several times for each post.
 * HTML output can be filtered with 'the_date'.
 * Date string output can be filtered with 'get_the_date'.

So what exactly represents thes 2 variable? and why if they are the same the date is not returned? How can I fix this problem and show the date?

2 Answers 2


For historical bloggy reasons, the_date in WordPress won't show the same date twice in a row. This is for grouping purposes.

The fix is easy: Use the_time instead. It behaves exactly the same as the_date, but without the internal historical logic. Also no need to rewrite any complicated code, just change three characters. :)

Note: the_time is missing the before, after, and echo parameters, but that's okay because you really don't need them. It always echo's, and you can put the before and after parameters surrounding it quite easily. Like I said, there are historical reasons for the operational behavior of the_date, which don't make sense except in specific circumstances which generally don't apply anymore.


As it says right there is its inline documentation — the function is meant to only output the result "once per date". In typical chronological loop of posts it will "collapse" for posts made on same day. In less typical loop it might lead to pretty bizarre outputs.

If you dig far and deep enough in version control history you might be able to dig up reasoning for it.

From practical point of view you should just look through the source and take away that get_the_date() gets you the same stuff sans all the "once per" logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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