Solution: the_date() not working in WordPress

By Avinash

January 20, 2013Web Development3 Comments

While developing my this new theme I ran into the situation where date for some posts were not displaying. After some review I found this is occurs when I have multiple posts published on same day.

I was surprised with this behavior but after quick searching what I found is that I have made very silly mistake on this.

What I have missed is very first notice on the the_date() page of WordPress Codex. Let me copy the same line over here.

SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.

So basically the_date()) will show date only once for the same date posts that’s why I was not getting date for some posts.

Solution

// This won't show date in all cases the_date('F d, Y'); // This will show date in all cases the_time('F d, Y')
// This won't show date in all cases
the_date('F d, Y');

// This will show date in all cases
the_time('F d, Y')

Share This Article