I am setting up a site with a number of historical speeches made by our head of state, dating back to 1814. I want the dates these speeches are posted on to be the date they're given. This will give me the post slug I want: /yyyy/mm/postname. Also it will have a logical archive, as the speeches are sorted by date they're given, and not the date I posted them on the site.
But here's the problem. All posts are published on 1970-1-1, the unix 0 epoch. More so, when viewing the posts, the published date is always the current date. The post slugs are all /1970/01/postname, and the archive is full of posts made in 1970.
There's a bug in WP's trac about this: [[LINK href="http://core.trac.wordpress.org/ticket/10332"]][[/LINK]], but this bug keeps being pushed forward.
There are suggestions that this is a PHP problem and that I should contact my host about this. My host is mediatemple, and they run PHP 5.2.x, while the PHP issues are probably linked to PHP 5.1.0 and windows based servers. Also, it worked in WP 2.7.x -as you can see in the trac report.
Now I'm looking for someone who can fix that nasty bug, so I can move on with my site. There'll be about 200 speeches posted there, and I'd hate to have to go back and edit each and every one of them later on if and when this bug gets squashed.
Anyone willing to help fix this for real and for good, gets my eternal gratitude!
Herko Coomans
Bill Hunt answers:
1-1-1970 is the Unix Epoch - all timestamps are based on this date. Windows servers can't handle negative timestamps, so the only solution is to move to unix/linux-based host. I've tested this on Darwin (BSD) and it works perfectly, if that's at all encouraging. :)
The only workaround would be to use totally custom permalinks for every post, and edit each manually. I don't think this will help your ordering issues, though.
herko comments:
Hello Bill, thanks for looking into this issue!
Yes, I know about Unix Epoch. As I said, I'm hosted on Mediatemple's gridservice, a linux system with OS Type Linux n29 2.6.33.1 and PHP Version 5.2.6. And I don't want to host the site on my Mac (Darwin), as that's not on all the time.
So essentially, the (mt) gridservice should be able to handle negative timestamps, as it's not a Windows server. Also, it's not running PHP 5.1.0, for which some lines of code were added to WP 2.8 to deal with dates.
So it must be a bug in WordPress itself, as stated in the trac report.
Bill Hunt comments:
Sorry for underestimating you; I went back and read the full thread of the trac bug. I'm unable to reproduce the problem you're having with the page slugs - it's updating to the correct date for me upon hitting Update, even though it's showing the wrong published date in the post. The database has the correct data for me though - can you verify if it's storing the right date in mysql?
I've discovered that Wordpress' internal date handling seems to be a bit buggy in a few places: using the_time() and the_date() are definitely giving the wrong info. I had more success using date() wrapped around strtotime($post->post_date)
herko comments:
Thanks Bill for looking into this deeper :-)
I checked the database, the post_date field values are all correct, pre-1970 dates.
Strange thing is, on another linux server, with the same php version, the slug does work for me too.
I reuploaded the latest WP install, to make sure I have the full latest version.
What would you recommend I do with the post_post_date and where?
Bill Hunt comments:
Ok, so the magic for building permalinks is all in wp-includes/link-template.php - you're probably going to want to do some var_dump( ) a few things in get_permalink( ) to see exactly where the data is being mangled. It's getting the data and converting into unix time on line 113, and parsing it on line 138 - those are the most likely candidates for problems.
The $post->post_date will give you the raw database version of the date, as they're using in get_permalink() - you'll need to use that in your theme if you want to show the proper date in the post, instead of 1970 that will be given by the_date() and the_time().
herko comments:
Bill, thanks for pointing me in the right direction!
But debugging WP's more complex PHP is beyond my capabilities. I did a few var_dumps, and always got the current date and time, but what this means and where I should continue to look is beyond my skills.
Also, it works like it should (well, the published date showed is still the current date, so not completely), with the slug shown as 1850/3/postname on another linux server I have a few sites on. Thing is, (mt)'s service doesn't cover script related issues (even tho there's something on *their* system that's causing this), so they refuse to help me.
And actually doing a debug to see where this goes wrong requires more time for you then I am currently asking. But if you want to help, the prize money is yours, and I'll send you login details for the WP site, so you can perform the debugs.
If you don't feel like doing that (and I can imagine!), I'll leave this question open for another day and if no solutions are posted, the prize money is yours!
Bill Hunt comments:
Well, if you want to PM me the site url, wp login info, and ftp info, I can take a look - but I can't promise I can actually fix whatever is wrong. :) It might be server-related, and beyond what I could fix.
herko comments:
Yes, if it's server related, it can't be fixed (easily). But if I know what to tell the mediatemple staff, they may be able to fix it anyways. Right now, they see this as a WP problem.
Rok Don answers:
For URL Structure:
Go to Admin panel => Settings => permalinks
In this page under the common setting there are various options to set urls.
Choose Custom Structure and paste there below code
/%year%/%monthnum%/%postname%
This will solve your URL issue.
For date:
While adding any post there is option to select/edit publish date for your post. This option is available at right side in publish box above update button. you can give any date whatever you want. This date will apply for that post.
Hope above things will work with you.
Let me know still you have any issues.
herko comments:
To clarify: I have created and set up numerous WordPress sites, ever since WP 1.3 I think -years ago at least. I can read php code a bit -solving this issue is another matter entirely. I coded my own templates, so I know a bit how WP works. But this timestamp and date stuff is complex, as there's a LOT of interaction with PHP versions and server settings going on.
Anyways, thanks Rok Don for answering, but this isn't a configuration issue. The permalink structure is already set to /%year%/%monthnum%/%postname%, as that is what creates the /1970/01/postname slug. The problem is, that WP doesn't create a /1814/03/postname slug, even when the published date entered is changed to march 1814. When press 'save', the published date becomes the current date (and every time I see the post, it shows the current date, so it's a dynamic value), and the slug shows the unix 0 epoch date and time.
Solving this problem lies a bit deeper then just entering a date and setting the permalink structure.
Herko
Rok Don comments:
This issue is related to unix timestamp.
any invalid date is get converted to 1st jan 1970
herko comments:
Er, yes, that's what I said.
Thing is, since when is march 1814 an invalid date? And why is WordPress invalidating any and all dates prior to 1970?
Rok Don comments:
open your functions.php file in wp-includes folder
there is function called "date_i18n"
comment below code (if block) and it will work
/ Sanity check for PHP 5.1.0-
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;
}
herko comments:
Rok, thanks again for answering :-)
It seems the link to the trac report didn't make it to my question, but your answer is in that report, and it doesn't work.
The trac report is here: http://core.trac.wordpress.org/ticket/10332
Lew Ayotte answers:
That is very interesting... what version of WP are you using?
Lew
herko comments:
Hi Lew, thanks for answering my question! Or at least, showing interest :-)
I'm now using Wp 2.9.2, with Dutch language files. I've had this issue since WP 2.8 tho. And I'll have to recheck, but also without the localization (getting back to you on that).
For extra clarity, the symptoms are:
[1] When entering a published date prior to 1-1-1970 (european date format), the published date shown in the edit post screen becomes 1-1-1970, but the published date shown when viewing the post itself is the current date. This means that when you view the same post a day later, the published date is a day later then before.
[2] When permalink structure is set to /%year%/%monthnum%/%postname%, all post slugs are /1970/01/postname.
[3] Any reference to the pre-1970 date is no longer shown anywhere.
herko comments:
I just doublechecked, with the localization turned off, the problem still remains. So it is not an issue with date transformation for localization purposes.
paul de wouters answers:
maybe one way to do it would be using years and months as categories?
herko comments:
Hey Paul, thanks for replying!
Yes, that's a possible solution I guess. But it doesn't solve the bug.
But I'll keep this tip in mind if the bug isn't fixed!
Herko
herko comments:
Oh, and I'm already using the categories and tags for other purposes.
It's the yearly address of the King, and each monarch's reign is a category, and the tags are used for the topics the address is about.
Samuel Arendt answers:
I would use the <strong>taxonomy </strong>to mark the dates and avoid problems with publication date, I do not think some use. Publication date is related to publication of the post and not the date of the event.
<strong>Taxonomy </strong>provides you with a marquee for the semantic tageamento dates, it is much easier to tie dates and characters.
Ex.:
functions.php
<?php
register_taxonomy(
'date', 'post',
array(
'hierarchical' => true,
'label' => 'Event Date',
'rewrite' => array( 'slug' => 'date' )
)
);
register_taxonomy(
'people', 'post',
array(
'hierarchical' => false,
'label' => 'People Involved',
'rewrite' => array( 'slug' => 'people' )
)
);
?>
herko comments:
Hi Samuel, thanks for taking the time to answer this question!
In this case, the published date would be the date the speech is published. So semantically it would be correct to use it the way I want to be able to.
But I'll look into the taxonomy, it is new to me tho.
Also, I suspect you're using a translating service to translate your answer to English, and even tho the general meaning of your answer is clear, the details (and that is what it is probably about) aren't.
Samuel Arendt comments:
Exato! Sou brasileiro e não falo inglês.
<!-- google translate -->
Exactly! I am Brazilian and I do not speak English.