中的参数说明the Codex entry for wp_insert_post()
has exactly what you need (reformatted).
\'post_category\' => [ array(<category id>, <...>) ]
//post_category no longer exists, try wp_set_post_terms() for setting a post\'s categories
所以,根据法典。使用
wp_set_post_terms()
.
wp_set_post_terms( $post_id, array( 1, 2, 3), \'category\', true );
对于自定义分类:
\'tax_input\' => array(
\'taxonomy_name\' => array(
\'term\',
\'term2\',
\'term3\'
)
); // support for custom taxonomies.
只需将分类名称更改为所需名称并替换
term
具有所需类别段塞的占位符。
Codex弱暗示您不能再通过wp_insert_post()
. 然而,虽然我还没有测试过它,但如果tax_input
参数也适用于category
分类法,如:
\'tax_input\' => array(
\'category\' => array(
\'a\',
\'b\',
\'c\'
)
);