## functions – delete_term is not working properly with add_action()

Question

delete_term is not working, I’m trying to delete term and after I deleted it, it’ll also delete the similar term from different a taxonomy based on their slugs

here’s my code of the delete_term, so in the code below, when I deleted a term from movies_category taxonomy, it’ll look/find for a similar slug from category (the default wordpress taxonomy for Posts), and then delete it also programmatically, but the code doesn’t work on my end, I’m not sure where did I go wrong here.

function delete_similar_term($term_id,$tt_id, $taxonomy,$deleted_term) {
if( $deleted_term->taxonomy === 'movies_category' ) {$post_cat_term = get_term_by( 'slug', $deleted_term->slug, 'category' ); wp_delete_term($post_cat_term->term_id, 'category' );
}
}
add_action( 'delete_term', 'delete_similar_term' , 10, 3 );


It’s hard for me to debug this also because I can’t see any errors, when I delete a term from my movies_category it will just highlight the term red and AJAX delete stops working.

0
2 months 2023-02-03T17:03:18-05:00 0 Answers 0 views 0