我试图删除所有自定义分类对象,包括使用 WPML 进行的翻译。
$terms = get_terms('product-category');
foreach ($terms as $term) {
wp_delete_term($term->term_id, 'product-category');
}
这样做是删除所有主要语言分类,但保留所有翻译。什么是删除所有分类及其翻译的正确方法。同样重要的是,*_icl_translations 表中的翻译链接将被删除以用于分类。
您需要使用 icl_object_id 函数。IE:
icl_object_id( {term_id}, {taxonomy}, false, {language} );
这是完整的示例,易于理解:
$all_languages = icl_get_languages();
$terms = get_terms('product-category');
foreach ($terms as $term) {
wp_delete_term($term->term_id, 'product-category');
foreach ($all_languages as $lang => $row) {
if ($term_id = icl_object_id( $term->term_id, 'product-category', false, $lang )){
wp_delete_term($term_id, 'product-category');
}
}
}