greencode
Member
Posted 1 year ago #
I've been trying to add content that needs to be dated pre-1970 but have noticed it doesn't seem to stick to that date and instead displays today's date. I've had a hunt around and it does seem this is an ongoing issue. Does anyone know of any way to resolve it other than me having to create a custom field to add the date?
Hi,
It sounds very much like you've run into a Unix system limitation. The operating system "starts" on the last day of 1969.
http://www.seroundtable.com/archives/000982.html
So if you're using a Unix date function, then that would explain it, and you'll likely need to make something custom for that.
cheers
greencode
Member
Posted 11 months ago #
Now then I've looked around and found this post http://wordpress.org/support/topic/pre-1970-dates-no-longer-handled-correctly?replies=12 which says to comment out this code in the wp-includes/functions.php file:
if ( false === $i || intval($i) < 0 ) {
if ( ! $gmt )
$i = current_time( 'timestamp' );
else
$i = time();
// we should not let date() interfere with our
// specially computed timestamp
$gmt = true;
}
which works perfectly and now dates are displaying as far back as I need i.e. 1932 but a couple of things:
1. Is it okay to do this i.e. will it affects anything else and…
2. Is there are a better way of doing this so when I update WordPress I don't have to update that file each time?
greencode
Member
Posted 11 months ago #
Well, I've gone ahead and done the above and all's working well. Just need to remember to comment out the code on each new WordPress release!
Don't edit core code! Apart from the risk of breaking your entire site, you may create security loopholes in your WordPress install.
Is there are a better way of doing this
Yes. Use custom fields for pre-1970 dates in the format yyyy-mm-dd.
greencode
Member
Posted 11 months ago #
Hi. Thanks for this - can you explain what code I would enter and how I would display it in my template. Thanks.
See Using_Custom_Fields. You can suppress the real post date in your theme's template files and even display posts in pre-1970 "date" order by using a custom query.
http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Function_Reference/WP_Query
greencode
Member
Posted 11 months ago #
I ended up using this:
<?php if( $image = get_post_meta($post->ID, "year", true) ): ?>
<?php echo $image; ?>
<?php else: ?>
<?php the_time('Y') ?>
<?php endif; ?>
My company's outlined a temporary workaround here, and a full-fledged WordPress plugin is in the works. We'll release it in the next few weeks.
Keep an eye on the SH site, our Google Code project site, and the SH WordPress plugins pages:
- http://studiohyperset.com/projects/wordpress-plugins
- http://profiles.wordpress.org/users/studiohyperset/
... for more details.