If you do not pass a date to wp_insert_post()
, get_gmt_from_date()
is called. And look at that function’s content:
function get_gmt_from_date($string, $format="Y-m-d H:i:s") {
preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
if ( ! $matches )
return date( $format, 0 );
$tz = get_option('timezone_string');
if ( $tz ) {
date_default_timezone_set( $tz );
$datetime = date_create( $string );
if ( ! $datetime )
return date( $format, 0 );
$datetime->setTimezone( new DateTimeZone('UTC') );
$offset = $datetime->getOffset();
$datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours');
$string_gmt = gmdate($format, $datetime->format('U'));
date_default_timezone_set('UTC');
} else {
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
$string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * HOUR_IN_SECONDS);
}
return $string_gmt;
}
It changes the time zone according to the setting in the option timezone_string
. So go to wp-admin/options-general.php
and set the proper time zone. Or pass a valid date per parameter post_date
.