我从API服务器获得我的类别
{name: "Apple", id: "2", parent_id: "0"}
{name: "Gree aple", id: "50519", parent_id: "2"}
然后添加查询数据库
foreach ($data as $term) {
$unique_id = 50000;
$res = $wpdb->query(
$wpdb->prepare(
"INSERT IGNORE INTO wp_terms ( term_id, name, slug ) VALUES ( %d, %s, %s )",
$term['id'] + $unique_id,
$term['name'],
$term['id'].'_slug'
)
);
if($term['parent_id'] == 0)
{
$term['id'] = $term['id'] + $unique_id;
$unique_id = 0;
}
$res2 = $wpdb->query(
$wpdb->prepare(
"INSERT IGNORE INTO wp_term_taxonomy ( term_id, taxonomy, parent ) VALUES ( %d, %s, %d )",
$term['id'] + $unique_id,
'product_cat',
$term['parent_id'] + $unique_id
)
);
}
分层的自定义分类法未在管理面板中通过编程添加来显示子级。但是,当按管理面板类别“ Apple”(更新按钮)进行更新时,会按层次显示。我的代码有什么问题?