【问题标题】:Wordpress: How can I add terms to a custom taxonomy?Wordpress:如何将术语添加到自定义分类?
【发布时间】:2015-06-29 19:32:01
【问题描述】:
$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
    );
}

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

谢谢。

【问题讨论】:

  • 你上面的代码有什么问题?

标签: php wordpress foreach custom-taxonomy


【解决方案1】:

我的错误是我没有启动函数。

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' );

【讨论】:

    猜你喜欢
    • 2014-08-16
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 2019-06-09
    • 2012-07-11
    • 2012-08-09
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多