您必须分两步完成此操作。首先,您将使用wp\\u insert\\u post()在草稿模式下创建一篇文章。wp\\U insert\\U post本身将向您返回插入帖子的ID:
<?php
$new_post = array(
\'post_title\' => \'Draft title\',
\'post_status\' => \'draft\'
\'post_type\' => \'my_custom_type\'
);
$postId = wp_insert_post($new_post);
?>
<form method="post" action="your-action.php">
<p>Hey! You are creating the post #<?php echo $postId; ?></p>
<input type="hidden" name="draft_id" value="<?php echo $postId; ?>">
...
</form>
之后,在操作页面中,您将获得草稿id并更新帖子。您将使用wp\\u update\\u post通知草稿ID。
<?php
$draftId = $_POST[\'draft_id\'];
...
$updated_post = array(
\'ID\' => $draftId,
\'post_title\' => $title,
...
\'post_status\' => \'publish\', // Now it\'s public
\'post_type\' => \'my_custom_type\'
);
wp_update_post($updated_post);
?>
希望有帮助:)