首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wp_insert_post错误:“内容、标题和摘录为空。”

wp_insert_post错误:“内容、标题和摘录为空。”
EN

Stack Overflow用户
提问于 2013-09-12 19:10:37
回答 1查看 5K关注 0票数 1

我试图通过PHP将WooCommerce产品插入到WordPress数据库中。WooCommerce产品只是一个post类型= product的帖子,所以我认为这应该是可行的:

代码语言:javascript
复制
$mypost = array('post-title' => $secondexplosion[0], 'post-type' => 'product',
   'post-status' => 'publish', 'post-content' => $secondexplosion[1],
   'post-excerpt' => '');
$postid = wp_insert_post($mypost, true);

$secondexplosion是一个字符串数组,包含post标题和post内容;我检查了它,它不包含空值或任何问题。那么,为什么wp_insert_post返回错误“内容、标题和摘录为空”?非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-12 19:14:02

帖子有很多有用的信息:

代码语言:javascript
复制
$post = array(
  'ID'             => [ <post id> ] //Are you updating an existing post?
  'menu_order'     => [ <order> ] //If new post is a page, it sets the order in which it should appear in the tabs.
  'comment_status' => [ 'closed' | 'open' ] // 'closed' means no comments.
  'ping_status'    => [ 'closed' | 'open' ] // 'closed' means pingbacks or trackbacks turned off
  'pinged'         => [ ? ] //?
  'post_author'    => [ <user ID> ] //The user ID number of the author.
  'post_category'  => [ array(<category id>, <...>) ] //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
  'post_content'   => [ <the text of the post> ] //The full text of the post.
  'post_date'      => [ Y-m-d H:i:s ] //The time post was made.
  'post_date_gmt'  => [ Y-m-d H:i:s ] //The time post was made, in GMT.
  'post_excerpt'   => [ <an excerpt> ] //For all your post excerpt needs.
  'post_name'      => [ <the name> ] // The name (slug) for your post
  'post_parent'    => [ <post ID> ] //Sets the parent of the new post.
  'post_password'  => [ ? ] //password for post?
  'post_status'    => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | 'custom_registered_status' ] //Set the status of the new post.
  'post_title'     => [ <the title> ] //The title of your post.
  'post_type'      => [ 'post' | 'page' | 'link' | 'nav_menu_item' | 'custom_post_type' ] //You may want to insert a regular post, page, link, a menu item or some custom post type
  'tags_input'     => [ '<tag>, <tag>, <...>' ] //For tags.
  'to_ping'        => [ ? ] //?
  'tax_input'      => [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // support for custom taxonomies. 
);  

看起来您的字段中有一个错误;预期的字段名是post_titlepost_typepost_statuspost_contentpost-excerpt --这是带有下划线的,而不是破折号。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18772504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档