我在更新post_date
在我编写的自定义函数中。
我想改变post_date
按我的习惯meta_date
价值
功能如下:
function cfc_reset_postdate( $data, $postarr ) {
// If it is our form has not been submitted, so we dont want to do anything
if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) return;
if($data[\'post_type\'] == \'scripture-memory\') {
$date = get_post_meta( get_the_ID(), \'cfc_date\', true );
$date = DateTime::createFromFormat(\'D - M j, Y\', $date);
$date = $date->format(\'Y-m-d\');
$data[\'post_date\'] = $date;
return $data;
}
add_filter( \'wp_insert_post_data\', \'cfc_reset_postdate\', \'10\', 2);
它可以工作,除非我必须按
Update 按钮两次以更改
post_date
以匹配我的新元日期。
我在线阅读了wp includes中的一些内容2380:
如果$postarr参数的“ID”设置为值,则将更新post。
我不知道这意味着什么,但我认为这可能会帮助我解决这个问题。
我做错了什么?
EDIT:
下面是我发送到meta box插件的代码:
$prefix = \'cfc_\';
global $meta_boxes;
$meta_boxes = array();
// 1st meta box
$meta_boxes[] = array(
// Meta box id, UNIQUE per meta box
\'id\' => \'scripture_memory_verse\',
// Meta box title - Will appear at the drag and drop handle bar
\'title\' => \'Scripture Memory Verse\',
// Post types, accept custom post types as well - DEFAULT is array(\'post\'); (optional)
\'pages\' => array( \'scripture-memory\' ),
// Where the meta box appear: normal (default), advanced, side; optional
\'context\' => \'normal\',
// Order of meta box: high (default), low; optional
\'priority\' => \'high\',
// List of meta fields
\'fields\' => array(
array(
// Field name - Will be used as label
\'name\' => \'Reference\',
// Field ID, i.e. the meta key
\'id\' => $prefix . \'reference\',
// Field description (optional)
\'desc\' => \'If you don\\\'t spell the book correctly, the verse won\\\'t show up!\',
// CLONES: Add to make the field cloneable (i.e. have multiple value)
\'clone\' => true,
\'type\' => \'text\'
),
array(
\'name\' => \'Day\',
\'id\' => "{$prefix}date",
\'type\' => \'date\',
\'desc\' => \'(What Sunday are we saying this verse)\',
// Date format, default yy-mm-dd. Optional. See: http://goo.gl/po8vf
\'format\' => \'DD - M d, yy\'
)
)
);