Wordpress:如何在自定义分类中添加术语?

时间:2015-04-22 08:59:43

标签: php wordpress foreach custom-taxonomy

$terms = array('Audio','CD','Download','DVD','Publication','Website');
foreach( $terms as $term ) {
   //intert the term
   wp_insert_term(
        $term, // the term 
        'media-type' // the taxonomy
    );
}

如果可能,我也希望这些条款成为唯一的条款,并阻止用户添加更多条款。

感谢。

1 个答案:

答案 0 :(得分:0)

我的错误我没有启动功能。

function insert_terms() {
  $terms = array('Audio','CD','Download','DVD','Publication','Website');
  foreach( $terms as $term ) {
       //intert the term
       wp_insert_term(
            $term, // the term 
            'media-type' // the taxonomy
        );
  }
}

add_action( 'init', 'insert_terms' );