数组如何插入帖子类别和子类别?
谢谢
数组如何插入帖子类别和子类别?
谢谢
中的参数说明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\'
)
);
Worked for me with wp_set_object_terms()
我正在使用wp\\u list\\u categories()显示我的所有类别。但我希望子类别链接到该类别的最后一个帖子。例如: <ul> <li><a href=\"link-to-category-1\">CATEGORY 1</a> <ul> <li><a href=\"link-to-last-post-of-category-1-1\">CATE