【发布时间】:2011-12-07 15:15:07
【问题描述】:
我设置了一个名为“照片”的自定义内容类型,它运行良好。现在我正在使用 wp_insert_post() 插入具有该内容类型的帖子,并且在添加类别时遇到问题。这些是我与帖子类型关联的分层类别,可以在管理区域中设置,但我尝试使用 PHP 代码关联它们,它不起作用。
这里是sn-p的代码:
$new_entry = array();
$new_entry['post_title'] = $_POST['submit-title'];
$new_entry['post_content'] = '';
$new_entry['post_status'] = 'pending';
$new_entry['post_type'] = 'photo';
$new_entry['post_author'] = $userID;
$new_entry['post_category'] = array(6,7); // this is the line that doesn't work
$new_entry['tags_input'] = array('nature','people','fun'); // this also doesn't work
// Insert the post into the database
$post_id = wp_insert_post( $new_entry );
这一切正常,自定义帖子已插入并按预期显示,但没有分配任何类别。 (类别 6 和 7 是应该与“照片”帖子类型相关联的类别)。不仅如此,这些标签也不会被创建并与这篇文章相关联。
有人对我做错了什么或他们推荐的其他方法有任何想法吗?
【问题讨论】:
标签: wordpress post tags categories