我在插入字词方面确实遇到了一些问题。这是我的场景:我有一个名为veda_release_type的分类法:
//Release Type and Region
$labels = array(
'name'=> _x('Release Types/Regions', 'taxonomy general name' ),
'singular_name' => _x('Release Type/Region', 'taxonomy singular name'),
'search_items' => __('Search Release Types/Regions'),
'popular_items' => __('Popular Release Types/Regions'),
'all_items' => __('All Release Types/Regions'),
'edit_item' => __('Edit Release Type/Regions'),
'edit_item' => __('Edit Release Type/Region'),
'update_item' => __('Update Release Type/Region'),
'add_new_item' => __('Add New Release Type/Region'),
'new_item_name' => __('New Release Type/Region Name'),
'separate_items_with_commas' => __('Seperate Release Types/Regions with Commas'),
'add_or_remove_items' => __('Add or Remove Release Types/Regions'),
'choose_from_most_used' => __('Choose from Most Used Release Types/Regions')
);
$args = array(
'hierarchical' =>true,
'labels' => $labels,
'query_var' => true,
'rewrite' => array('slug' =>'release_type')
);
register_taxonomy('veda_release_type', 'veda_release',$args);
这显然是荒唐的。顶层包含发行类型,例如DVD,蓝光。在该级别下的是区域,即。区域1,区域2等。因此,我想要的层次结构是:DVD –区域0 –区域1 –区域2 –区域3 –区域4 –区域5 –区域6 Blu-Ray- -区域A-区域B-区域C
我在类中创建了一个名为insert_term的函数,以检查术语是否存在,如果不存在,则将其插入:
public function insert_term ($term, $taxonomy, $args = array()) {
if (isset($args['parent'])) {
$parent = $args['parent'];
} else {
$parent = 0;
}
$result = term_exists($term, $taxonomy, $parent);
if ($result == false || $result == 0) {
return wp_insert_term($term, $taxonomy, $args);
} else {
return (array) $result;
}
}
然后我调用所说的函数来插入术语:
$dvd = $this->insert_term('DVD','veda_release_type');
$this->insert_term('Region 0','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 1','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 2','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 3','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 4','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 5','veda_release_type',array('parent'=>$dvd['term_id']));
$this->insert_term('Region 6','veda_release_type',array('parent'=>$dvd['term_id']));
$bd = $this->insert_term('Blu-Ray', 'veda_release_type');
$this->insert_term('Region A','veda_release_type',array('parent'=>$bd['term_id']));
$this->insert_term('Region B','veda_release_type',array('parent'=>$bd['term_id']));
$this->insert_term('Region C','veda_release_type',array('parent'=>$bd['term_id']));
我遇到的问题是,即使在数据库中输入了术语,它们也不会显示在分类页面上。最多显示顶级术语。我必须尝试各种尝试,直到它迫使WordPress识别次级术语为止。有没有人遇到这个问题或可以推荐更好的方法?
编辑:注意其他事项:我试图从数据库中删除这些条款,然后停用并重新激活声明该条款的插件。两个父术语显示在术语页面中,但子术语则不显示。子条款确实显示在要创建新条款的“父母”下拉菜单中。当我添加一个其父代是子术语之一的术语并刷新页面时,将显示子术语。