我使用前端编辑器做了一个项目。正如@martinczerwi 所说,您必须维护访问权限(角色管理)。
这是我的代码示例,请从 id 获取想法,我想您了解编码
if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
$cpostStatus = 'draft';
if(isset($_POST['proStatus'])){
$cpostStatus = trim($_POST['proStatus']);
}
if(trim($_POST['projectName']) == '') {
$projectNameError = 'Please enter a Project Name.';
$hasError = true;
} else {
$projectName = trim($_POST['projectName']);
}
if(!$hasError){
$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['projectName'])),
'post_content' => esc_attr(strip_tags($_POST['projectDescription'])),
'post-type' => 'post',
'post_status' => $cpostStatus
);
**$post_id = wp_insert_post($post_information);**
if($post_id)
{
// Update Custom Meta - your custom data
update_post_meta($post_id, 'citerp_start_date', esc_attr(strip_tags($_POST['startDate'])));
// Redirect
wp_redirect( home_url('/projects') ); exit;
}
}
}
与插入使用更新部分相同
$post_information = array(
'ID' => $current_post,
'post_title' => esc_attr(strip_tags($_POST['projectName'])),
'post_content' => esc_attr(strip_tags($_POST['projectDescription'])),
'post-type' => 'post',
'post_status' => $cpostStatus
);
$post_id = wp_update_post($post_information);