// Auto post (Unique File Date).
$postData = array(
'post_category' => array('0'),
'post_status' => $Post_Status,
'post_type' => $Post_Type,
'post_date' => $File_Individual_Date
);
wp_insert_post($postData);
当使用'post_category' => array('0'),
时,它在类别Uncategorised
下添加一个帖子。如果我在var中有一个类别可以说:在wordpress中添加类别 - 自定义
$myCategory = 'News'
;
然后使用'post_category' => $myCategory
给出错误,并且没有添加新帖子。是否有可能以这种方式添加类别?
好的。这意味着我不能以这种方式创建一个类别?我首先需要从wp-admin创建一个类别,然后选择它的ID?我对吗? @Pieter Goosen –
好吧,看来你的问题有点不清楚。您想要将一个类别分配给尚未创建的帖子。您需要首先创建该类别,然后才能将其分配给某个帖子。看看['wp_insert_category'](http://codex.wordpress.org/Function_Reference/wp_insert_post) –
哦,所以我真的需要先从后端(wp-admin)创建一个类别,然后将其分配给帖子。谢谢。 –