【发布时间】:2014-01-22 03:19:54
【问题描述】:
我的目标是通过我创建的自定义前端表单将新的草稿帖子插入数据库。我需要帖子标题和内容为空。这可能吗?
我尝试了以下不起作用:
$post_data = array(
'post_title' => '',
'post_type' => 'post',
'post_content' => '',
'post_status' => 'draft',
'post_author' => 1
);
$post_id = wp_insert_post( $post_data );
注意:您可以使用带有空标题和内容的后端编辑器创建新帖子,所以我想知道 WordPress 的人是如何做到的。
【问题讨论】:
-
你有什么错误吗?
wp_insert_post( $post_data, true );应该返回一些:) -
是的,我得到一个“内容、标题和摘录”是空的。 var转储:object(WP_Error)#34 (2) { ["errors"]=> array(1) { ["empty_content"]=> array(1) { [0]=> string(38) "内容,标题,摘录为空。” } } ["error_data"]=> 数组(0) { } }