I finally found the solution to delete all the postmeta
related to the term being deleted.
For this, we need to use the action hook 'delete_term_taxonomy'
because it is executed before the term is deleted; therefore, we can find the term object and use it inside the hook.
Then, we proceed to perform certain task such as deleting all postmeta related to the term.
Here is the code:
add_action( 'delete_term_taxonomy', function($tt_id) {
$taxonomy = 'category';
$term = get_term_by('term_taxonomy_id', $tt_id, $taxonomy);
$user_name = $term->name;
$meta_key = "_category_relation_added_" . $user_name;
delete_post_meta_by_key( $meta_key );
}, 9, 1);
Related Posts:
- What is the action hook that deletes a taxonomy term from the backend? And how to retireve the term id before deleting it?
- Hierarchical taxonomy UI
- ‘wp’ action hook not firing in admin and login?
- get_term and get_term_by return null or false, even though term exists
- Display taxonomy with a maximum number of letters
- Change order of Custom Taxonomy List
- How to get current term in my custom taxonomy in WordPress?
- Custom order of terms for custom taxonomy in admin and website
- Front End Post Save Child terms
- Taxonomy slug by term ID
- Dropdown: Display terms from B only if has relationship with a term A selected
- wp_get_object_terms – How can I order the resulting array by hierarchy?
- Get current term’s ID
- Showing posts by collection of specific terms and texonomy
- How to use create_term, edit_term, delete_term actions?
- WP_insert_term how to insert multiple values as taxonomny term?
- term_link() filter or rewrite and howto?
- Custom Taxonomy terms with latest post ordered by date pagination issue
- How to set hierarchical terms to a post using wp_set_object_terms
- Echo taxonomy term meta on author.php
- Hierarchical display of custom taxonomy
- Custom taxonomy term as class?
- Advanced custom fields – taxonomy terms images [closed]
- Custom taxonomy term in WooCommerce product permalink
- List only first-level children of specific custom taxonomy term
- get_terms of post->id
- get / list categories and counts filtered by custom taxonomy term
- How to get a list of taxonomy terms which are being used only within certain post types?
- WPML Translating a term/taxonomy programmatically
- Allow only 1 instance of each term in each custom taxonomy
- Outputting an array of term meta values in a custom WooCommerce tab?
- Get terms from posts submitted within a certain time
- Display Terms for all posts in Current Archive or Query
- get_terms: determine if taxonomy term has children
- Display post taxonomies tree
- get_term_children returns WP_Error for custom taxonomy
- Exclude Taxonomy Terms from Template Via Back End?
- Displaying terms by first letter
- Print terms with taxonomy and metabox value
- Get custom category image from menu
- Same taxonomy for different object types
- Can I use a Custom Meta Value inside of ‘get_the_terms’?
- How to show all possible parents and children of a hierarchical taxonomy term?
- Failure to add term meta
- Hierarchical Taxonomy Terms Select Menu Output with selected=”selected” Set
- Can’t set custom taxonomy terms via custom form
- get_terms not returning any custom taxonomies
- Search Query for Multiple Terms In Same Taxonomy
- What does ‘category__in’ mean in queries?
- How to Modify Default Text in a Custom Taxonomy Admin Panel?
- How to write sql query to get the posts from a custom taxonomy term name
- Get only immediate children (and not grandchildren) of a hierarchical custom taxonomy term
- How to get_the_term_list() from multiple taxonomies?
- How to group all terms children’s in custom taxonomy?
- Reverse order of posts in a certain taxonomy archive?
- Display Posts by Custom Taxonomy Chosen Terms
- How to display a custom taxonomy without a link?
- Build filter for post-type + multi taxonomies + multi terms
- How do I get term data associated with the current post, where the result is not wrapped in HTML?
- wp_dropdown_categories – how to save in widget?
- echo a specific custom taxonomy term on a different custom taxonomy archive
- The best way to display taxonomies
- How to show post list based on taxonomy term?
- get_term_by works but get_terms doesn’t?
- Display empty custom taxonomies differently than with one with posts
- Double slash in the_terms URL
- How to call a custom taxonomy term name inside a function?
- How to get this value inside RETURN
- How to list Custom Taxonomy
- Custom Taxonomy List with Children
- How to output taxonomy term (incl. link to archive) on author.php?
- Page for custom taxonomy
- Display Child Categories of Current Post ID
- Set two terms for a post when they differ only by an accent
- How can I show links for custom posts group by taxonomy current term and sub-term?
- How to use custom slug and custom templates for custom taxonomy?
- Infinite Scroll appending Next Product Category Term pages
- Listing Cities A custom taxonmy by selection order
- Count tags for current post and save into custom meta field (and update it on post edit)
- get parent and childs from hierarchcial taxonomy
- Add term to taxonomy programatically
- Get Highest and Lowest get_term_meta() value from Taxonomy Term
- Print Custom Taxonomy Term Name
- set_object_terms for custom taxonomy in custom post type – not working
- Resize $term attachment using url
- Product dimensions filter by taxonomy
- How can I pull the slug of a custom taxonomy and output it in a class?
- Custom button on custom taxonomy listing page
- switch statement for taxonomy content
- Permalink Rewrite to include Custom Taxonomy Term
- How To Display Selected Terms For Custom Taxonomy?
- Adding a query var to taxonomy term archive – gets redirected to the other taxonomy archive page
- displaying links if term is used
- How to include child terms within parent?
- stdClass::$labels /wp-includes/general-template.php undefined
- $term->taxonomy stripping out underscores
- How can I get parent term from a child term
- get_terms() – unexpected ‘=>’ (T_DOUBLE_ARROW) error
- delete_term is not working properly with add_action()
- Hide empty categories on widget