Historical Timestamps in WordPress

Jayvee Fernandez recently wrote on The Blog Herald about WordPress and it’s problems with historical timestamps.

A friend on Plurk asked whether it is possible to use actual historical dates on your blog’s CMS (i.e. 4th of July 1776 for Independence Day). I did some digging and there are posts that address this question.

While this is a neat idea, setting the post date to reflect the time period a work was created (e.g. a photo taken in 1985), it introduces some problems.

  1. You won’t be able to schedule posts to be published at a later date. Setting the timestamp to a historical date will cause it to go live immediately.
  2. Posts with historical dates won’t necessarily be seen on the homepage when they are published. As WordPress (by default) orders posts by date, users would have to browse the archives to find the post. If you’re a master of custom queries, you might be able to remedy it in some way.
  3. I’ve always thought of the post timestamp being the date of publication, not the date of the content’s creation.

Wouldn’t it work better to use custom fields? You could add a custom field, historical_date, to a post with the historical date you want. You could then retrieve the date and display it in your post template with this line:

<?php echo get_post_meta($post->ID, "historical_date", true); ?>

You could even expand upon this a little bit, and replace your template’s call to display the publication date with a bit of code that would display the historical date, and fall back to the publication date if the custom field is empty.

Just find the part of your template that looks something like this (it will be in index.php, single.php, and any other post template):

<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<small class="postdate"><?php the_time('F jS, Y') ?></small>

Then replace the post date part with something like this:

<small class="postdate">
<?php
$historical_date = get_post_meta($post->ID, "historical_date", true);
if ($historical_date != "") {
echo $historical_date;
} else {
the_time("F jS, Y");
}
?>
</small>