我在插入术语方面确实有一些问题。下面是我的场景:我有一个名为veda\\u release\\u 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);
这显然是等级制度。顶层包含发行类型ieDVD、blu-ray。下面的级别是区域,即区域1、区域2等。因此,我想要的层次结构是:DVD--区域0--区域1--区域2--区域3--区域4--区域5--区域6Blu射线--区域A--区域B--区域C
我在类中创建了一个名为insert\\u 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认识到次级术语。有没有人遇到过这种情况,或者可以推荐一种更好的方法?
编辑:注意到了其他一些事情:我尝试从数据库中删除这些术语,然后停用并重新激活声明这些术语的插件。两个父术语显示在术语页面中,但子术语不显示。子术语确实会显示在要创建新术语的“父”下拉菜单中。当我添加一个其父项是子项之一的项并刷新页面时,子项就会显示出来。