Reputation: 125
I need hooks if tags have removed, created and edited. I have not found them in the WordPress Codex / Function Reference.
For categories:
edit_category
create_category
delete_category
Has anyone encountered this problem?
Upvotes: 3
Views: 1083
Reputation: 92
You can use these action hooks that you can find in the Wordpress Codex:
To know taxonomy Action Hooks and Filter Hooks, can go to this link
For this case, you can use different Action Hooks:
Fired after cache has been cleaned. To execute before cache has been cleaned use create_{$taxonomy} action hook
add_action( "created_*your_taxonomy*", "fired_on_created_term_of_taxonomy", 10, 3 );
function fired_on_created_term_of_taxonomy( $term_id, $taxonomy_id, $args ){...}
This hook is fired before term cache has been cleaned. (For example: if in your function execute get_term($term_id)
you're going to have old term, not the updated term data)
add_action( "edit_example_taxonomy", "fired_on_edit_term_of_taxonomy", 10, 3 );
function fired_on_edit_term_of_taxonomy( $term_id, $taxonomy_id, $args ){...}
This hook is very similar to hook before, but for example, you execute get_term($term_id)
in the fired function, you're going to have the updated term
add_action( "edited_example_taxonomy", "fired_on_edited_term_of_taxonomy", 10, 3 );
function fired_on_edited_term_of_taxonomy( $term_id, $taxonomy_id, $args ){...}
Fired on delete term of taxonomy
add_action( "delete_example_taxonomy", "fired_on_delete_term_of_taxonomy", 10, 4 );
function fired_on_delete_term_of_taxonomy( $term_id, $taxonomy_id, $deleted_term, $object_ids ){...}
Upvotes: 0
Reputation: 7611
To explicitly target tags, you'll need create_$taxonomy
, edit_$taxonomy
and delete_$taxonomy
where $taxonomy
is post_tag
(ie create_post_tag
, edit_post_tag
and delete_post_tag
). They're mentioned in passing in (eg) the wp_insert_term
.
Tags are a taxonomy, so the generic actions create_term
, edit_term
, and delete_term
would work as well, though they'll also fire for other taxonomies (such as categories).
Upvotes: 3
Reputation: 821
You need to use dynamic hooks to taxonomies:
edit_post_tag
create_post_tag
delete_post_tag
Upvotes: 3