我试图在创建时将类别数组分配给自定义帖子类型,因此我编写了以下代码:
$post_id = wp_insert_post( array(
\'post_content\' => \'\',
\'post_name\' => $title_slug,
\'post_title\' => $title_slug,
\'post_status\' => \'publish\',
\'post_type\' => \'test\',
\'post_author\' => \'me\',
\'post_excerpt\' => \'\',
// \'post_date\' => $date,
\'post_category\' => $categories_id,
// \'tags_input\' => array($tags)
));
//print_r($post_categories );
print_r($categories_id);
wp_set_post_categories( $post_id, $categories_id) ;
但它不起作用,没有类别受自定义帖子的影响,即使print_r($categories_id)
返回以下数组Array ( [0] => 51 [1] => 52 [2] => 53 [3] => 54 [4] => 55 [5] => 54 )
这是类别id的列表。有什么想法吗?