hey akaalvin,
I ended up having to write the code myself. it was quite a mission and requires javascript to be enabled.
I had to create a new table in the WP database. I called mine wp_todaysid. The fields are ID, storedDate and randomID
When a user visits the site, it loads the main site index.php and gets today’s date from the browser (using Javascrpt – client side headers don’t contain date info). Then it checks the above table to see if that date is already there. If it is (i.e. someone has visited the site that day), then use the date and the corresponding ID to display that post. If the date is a new one (for that day), then lookup all WP posts IDs (filtering out any unwanted pages, posts etc). Generate a random ID from all those IDs. Put the random ID into the wp_todaysid table. Then place that ID into a session variable. Then load the index.php file for your template and display that post.
This works well because it doesn’t matter what time zone a person is in. The key thing is the date that Javascript returns is the local system date. If they’re in New Zealand and 12 hours ahead of the UK for example, the UK users will still be looking for yesterday’s date. By the time the UK users gets to the next day, the NZ users will have generated a random ID. It means that Kiwis might always be generating IDs, but early bird gets the worm! And it’s all random anyway…
Here is the process the site index.php file goes through to handle the date:
– Get local date from browser (using Javascript)
– Because you can’t pass the Javascript date variable to the PHP (the script has already executed), you have to reload the page, passing the date to the URL
– If date exists in the URL, get it and store in session variable. Reload page.
– Third reload checks for session variable and continues.
– Using date from session variable, connect to database and check wp-todaysID table for today’s date
– If date exists in table, load template index.php file using the post ID corresponding to today’s date
– If date doesn’t exist, generate a random id, store ID and today’s date in wp-todaysID table. Then load your template index.php file using the post ID corresponding to today’s date
If you want to send me your email, I can send the code across
Regards,
Bryan