再看一遍,你似乎要插入两次帖子。wp\\U insert\\U post返回以下内容(来自codex):
如果帖子成功添加到数据库,则为帖子的ID。失败时,如果$wp\\u error设置为false,则返回0;如果$wp\\u error设置为true,则返回wp\\u error对象。
因此,如果提交了表单,您希望检查$thisid上是否有错误:
<form action="" method="post">
<input type="submit" value="Test" id="submit" name="submit">
<?php
// if post submit is set
if(isset($_POST[\'submit\'])){
// setup the post parameters, best not to call this $post
// as that may interfere with the global $post var in WP
$postargs = array(
\'post_title\' => $column1,
\'post_status\' => \'draft\',
\'post_type\' => \'bedrijf\'
);
// attempt to insert the post
$thisid = wp_insert_post ( $postargs, true);
// if there was an error, return the codes
if ( is_wp_error($thisid) ) {
return get_error_codes();
// if not, update the meta
} else {
update_post_meta( $thisid, \'field_1223ewedwd3123\', $column2);
}
}
?>
</form>
此外,您似乎正在更新ACF字段?如果是这样,您应该在update\\u post\\u meta上使用它们的update函数。其更新功能将确保根据字段类型正确格式化数据:
http://www.advancedcustomfields.com/resources/functions/update_field/