AFAIK, slug
is unique. So $post_cat_term = get_term_by( 'slug', $deleted_term->slug, 'category' );
shouldn’t return anything.
Instead, you may try name
.
Also, delete_term
callback gets 5 parameters, so it’s better to adjust that accordingly.
See if the following works:
function delete_similar_term( $term_id, $tt_id, $taxonomy, $deleted_term, $object_ids ) {
if( $deleted_term->taxonomy === 'movies_category' ) {
$post_cat_term = get_term_by( 'name', $deleted_term->name, 'category' );
wp_delete_term( $post_cat_term->term_id, 'category' );
}
}
add_action( 'delete_term', 'delete_similar_term' , 10, 5 );
Related Posts:
- Extract image from content and set it as the featured image
- Add action hook conditionally – only when home.php in use
- How can I tell if I’m on a login page? [duplicate]
- Using get_terms for custom taxonomy in functions.php
- How to hook into the quick edit action?
- WooCommerce add_action hook results in 500 error
- How to preserve edits to Name or Slug of term when using wp_update_term on save?
- Accepted arguments value in hook functions
- Which action hook to use for function?
- Modify a function without editing template
- Don’t delete a page if it holds users
- Which action does wp_update_user triggers?
- How can I get my Script to work on the Login page?
- Trigger a custom function when option are saved in admin area
- jQuery does not work
- Override the WordPress core function wp_referer_field
- Is there a way to prevent a function/method from being called outside a specific hook?
- Adding code before post title with the_title produces weird results
- Add back in child theme what the parent theme removed with remove_action
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- Replace admin header logo with an image
- Using get_terms for custom taxonomy in functions.php
- Does hook have an effect on increasing the page load?
- Save_post – Warning: Cannot modify header information
- What is the earliest Hook a Script can use?
- How Do I Unhook This Parent Theme Function?
- WordPress hooks to call a function inside a construct
- remove_action on after_setup_theme not working from child theme
- Issues with title-tag and document_title_parts
- Trying to use add_action and do_action with parameters
- Define custom Page Template without its own .php file
- Perform an action when post is updated/published
- Issue with get_theme_mod returning a blank value instead of the saved value
- add_action in a function, is it possible?
- why doesnt is_home() work in functions.php
- In WooCommerce I need to modify the thankyou.php page [closed]
- Change meta tags programatically
- Convert hyphen to underscore in permalinks
- Change parent theme file function in child themes functions.php
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- Reuse variable in hook callback
- gform_after_submission content appears immediately after , not in post body [closed]
- How do I change parameters without changing the core
- Hooking new functions to actions + passing parameters
- How to update feed only 2-3 times a week (for Feedburner email)?
- Increment price for Woocommerce Minicart [closed]
- how to change link of some wordpress pages
- Passing arguments to my function with do_action and add_action is not working
- How to properly add function called by action-hooked function to functions.php?
- Add function to every post?
- Insert term when page is published – avoid duplicates after edits
- Passing values from a widget to a function within a plugin
- Execute a ultimate member action when user role is updated
- Add other social networks to TwentyNineteen_SVG_Icons class in child theme?
- Replace a menu with widget or a custom template file programmatically
- Wait a result before enqueue
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- Get User Login Data (date, time… )
- Function added using `add_action()` not being called
- How do I prevent term from being created on create_term hook?
- How to return hook data when multiple parameters are present?
- Remove a category from a post when saving a new post
- Control the srcset much more (not all sizes in it each time)
- How to add_filter html template to middle of content
- Scripts not loading when using the wp_enqueue_scripts action
- Are there action hooks for comments?
- current_user_can comma list vs OR (||) list
- login_headertitle is deprecated since version 5.2.0
- Writing a function to detect an event
- 400 Bad Request – JavaScript App calling Custom wp-json endpoint
- WordPress wraps span tags into p tags
- Get term slug by term id and then explode it
- Add Adsense code between job listings – wp job manager plugin
- Add action to custom Function
- Use add_action within template
- Problem with custom function when I go back with the browser
- How to place a div inside a function that creates a div
- template_redirect action only firing if logged in
- How to get taxonomy tree ids without running expensive loops
- How to use wp_enqueue_script properly?
- Issue passing action class to nested function. Admin Columns
- If has action not working as expected
- Is_Page doesnt detect my page
- How do you insert code into the sidebar?
- Use action, filter, or hook to append HTML to WordPress plugin function
- How to show only specific category post by user role without plugin and restrict all other cats
- taxonomy_edit_form_fields output after term fields
- Which method is more correct for removing WooCommerce Extensions menu item?
- How to echo the translated custom field?
- Sending Messages Back to the Template After Processing?
- custom COOKIE on custom page
- Settings in functions.php used by a plugin
- Why wp_ajax hooks doesn’t work?
- wp_get_current_user->user login returns %20 for spaces
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Why functions metaboxes is causing White Screen in Admin [closed]
- image_size with respect to aspect ratios
- Is there a hook that I can use when a fatal error occurs?
- How to get variable from other function inside class function using add_action for Ajax call