Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code to fix 01.01.1970 date problem in Types plugin (starting version 1.6.2+)
* Patch to correct wrong date format in dB in Types fields
* Add this code to your functions.php
function mass_update_date_fields_typesfunc() {
//Make sure $types_field_name is the exact field name as saved in database.
/* That's all, stop editing below! */
if ((!(empty($types_field_name_in_db))) && (!($types_unixdate_update_done))) {
$field_name= substr($types_field_name_in_db,5,$length);
if (($wpcf_fields) && (isset($wpcf_fields[$field_name]))) {
//Validate if this field is a date field
if ((isset($types_field_information['type'])) && ('date'==$types_field_information['type'])) {
global $wpdb;
//Get all post IDs, meta key and meta value
$postid_array = $wpdb->get_results($wpdb->prepare("SELECT post_id,meta_value FROM $posts_meta_table WHERE meta_key = %s AND meta_value <> ''",$types_field_name_in_db), ARRAY_A);
if ((is_array($postid_array)) && (!(empty($postid_array))) && (function_exists('Types_isValidTimeStamp'))) {
//Loop through the meta values
foreach ($postid_array as $k=>$values) {
if (isset($values['meta_value'])) {
//Validate if in Unix time
if (!($result_check)) {
//Attempt conversion to unix time
if ($unix_time_equivalent) {
//Successful conversion, update back
$successful_updating=update_post_meta($values['post_id'], $types_field_name_in_db, $unix_time_equivalent);
//Loop done
//Marked as done to make this script run only once
function Types_isValidTimeStamp($timestamp)
return ((string) (int) $timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= ~PHP_INT_MAX);
/** END OF CODE */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment