1
votes

Im trying to delete all custom taxonomy objects including translations made with WPML.

$terms = get_terms('product-category');
foreach ($terms as $term) {
    wp_delete_term($term->term_id, 'product-category');
}

What this does, is delete all main language taxonomies but all translations are left. What is the right way to delete all taxonomies with their translations. It's also important that translation links in *_icl_translations table would get removed for the taxonomies.

1

1 Answers

1
votes

You need to use icl_object_id function. i.e:

icl_object_id( {term_id}, {taxonomy}, false, {language} );

Here is full example for easy to understand:

$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');
        }
    }
}