我使用acf_form()函数在前端添加/更新posts。除了邮寄日期外,一切都很顺利。不知何故,它发布了一个非常古老的日期(1970/01/01)。我想把现在的日期改过来。这是我的代码:
$current_datetime = date('Y-m-d H:i:s');
acf_form_head();
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'submit_value' => __("Send", 'acf'),
'updated_message' => __("Suksess!", 'acf'),
'new_post' => array(
'post_type' => 'nyhet',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_category' => '',
'post_modified' => $current_datetime,
'post_modified_gmt' => $current_datetime,
),
'fields' => array('ingress', 'publisere_kun_pa_lokallagssiden', 'featured_image'),
'html_submit_button' => '<input type="submit" class="button box-button green save-content" value="%s" />',
));我知道,如果是当前日期,我不需要设置'post_modified‘和'post_modified_gmt’值。我尝试了没有这2,然后我尝试手动设置当前日期时间。但它总是插入那个奇怪的老约会。我在更新帖子方面也有同样的问题。
发布于 2018-09-13 13:01:03
WordPress有许多日期/时间函数
你应该需要:
acf_form_head();
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'submit_value' => __("Send", 'acf'),
'updated_message' => __("Suksess!", 'acf'),
'new_post' => array(
'post_type' => 'nyhet',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_category' => '',
'post_modified' => current_time( 'mysql' ),
'post_modified_gmt' => current_time( 'mysql' ),
),
'fields' => array('ingress', 'publisere_kun_pa_lokallagssiden', 'featured_image'),
'html_submit_button' => '<input type="submit" class="button box-button green save-content" value="%s" />',
));欲了解更多信息:
发布于 2018-09-13 12:53:06
看来1970/01/01是你的系统日期。看看你的配置。
http://php.net/manual/en/function.date.php
函数date使用给定的整数时间戳返回根据给定格式字符串格式化的字符串,如果没有给出时间戳,则返回当前系统时间。换句话说,时间戳是可选的,默认为time()的值。
https://stackoverflow.com/questions/52313568
复制相似问题