由于元数据字段已经存在,您应该更新它
您还应该计算wp\\U insert\\U post的时间。。。这是修改后的代码
尝试一下,如果遇到问题,请告诉我:
else {
$title = $_POST[\'post_title\'];
$meta_box1 = $_POST[\'wpcf-mob_no\'];
$meta_box2 = $_POST[\'wpcf-mob_amount\'];
$meta_box3 = $_POST[\'wpcf-mob_type\'];
$meta_box4 = $_POST[\'wpcf-mob_status\'];
$new_post = array(
\'post_title\' => $title,
\'post_status\' => \'publish\', // Choose: publish, preview, future, draft, etc.
\'post_type\' => \'loads\' //\'post\',page\' or use a custom post type if you want to
);
//save the new post
$pid = wp_insert_post($new_post, 10, 1);
// Do the wp_insert_post action to insert it
do_action(\'wp_insert_post\', \'wp_insert_post\', 10, 1);
update_metadata($pid, \'wpcf-mob_no\', $meta_box1, true);
update_metadata($pid, \'wpcf-mob_amount\', $meta_box2, true);
update_metadata($pid, \'wpcf-mob_type\', $meta_box3, true);
update_metadata($pid, \'wpcf-mob_status\', $meta_box4, true);
print \'<pre>\';
var_dump(array($new_post, $pid));
print \'</pre>\';
}