这是我用来在专用插件类别中插入分类术语列表的代码。上还可以直接将术语添加到主职位类别。
// ************** Add taxonomy
$taxonomy_term = "my_term";
$taxonomy_category = "my_taxonomy_category";
if (null !==(get_the_ID())) {
if ( taxonomy_exists( $taxonomy_category ) ){
// if the tag doesn\'t exist
if ( ! $term = term_exists( $taxonomy_term, $taxonomy_category ) )
// insert it and get its id
$term = wp_insert_term($taxonomy_term, $taxonomy_category, array() );
// Create a list of plugin tags meant to be inserted into dedicated plugin category
$list_taxonomy_term .= $taxonomy_term . ", " ;
}
}
if ( $term && !is_wp_error( $term ) ) {
// Link terms to plugin dedicated category
wp_set_post_terms(get_the_ID(), $list_taxonomy_term, $taxonomy_category, true);
// Add plugin tags to the current WordPress post main taxonomy if we want so
# wp_set_post_tags(get_the_ID(), $list_taxonomy_term, \'post_tag\', true);
}