我有一个包含要导入到“campsite district county”分类法的类别和子类别的数组。我的子类别没有插入正确的父类别。它们正在根级别插入。在进行了一些调查之后,我遇到了在每次插入之后清除分类缓存所需的信息,所以我这样做了,但我仍然有同样的问题。
$dist[]=array(\'Açores\',\'Angra do Heroísmo\');
$dist[]=array(\'Açores\',\'Corvo\');
$dist[]=array(\'Aveiro\',\'Águeda\');
$dist[]=array(\'Aveiro\',\'Anadia\');
foreach($dist as $d) {
$i++;
if(is_array($d)) {
if ($parent_term=term_exists(trim($d[0]), \'campsite-district-county\')) {
//do nothing - let\'s add the county bellow
} else {
//Adds district
$parent_term=wp_insert_term(trim($d[0]), \'campsite-district-county\');
delete_option("campsite-district-county");
wp_cache_flush();
echo \'<h1>\'.trim($d[0]).\'</h1>\';
}
$id_parent=intval($parent_term[\'term_id\']);
echo \'<p>*\'.$id_parent.\'*</p>\';
//Add county
$child_term=wp_insert_term(trim($d[1]), \'campsite-district-county\', array(\'parent\', $id_parent));
delete_option("campsite-district-county_children");
wp_cache_flush();
echo \'<p>\'.trim($d[1]).\'</p>\';
}
}