Solution: the_date() not working in WordPress

  • Avinash
  • 3
  • Jan 20, 2013
  • Web Development

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')

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: