I need some hooks especially for trashing and untrashing custom post types. However the hooks are not so clear in this case.

For example, to run a function on trash, I can use

     add_action('wp_trash_post','my_function');

However there doesn’t seem to be any other action specific to custom post types. So how would I execute my function on trashing of a custom post type?

1
1

Two action hooks run when a post is trashed wp_trash_post before the post is trashed and trashed_post afterwards. These run for any post type including attachments.

See wp-includes/post.php

If you want to limit your function to a specific post type you need to run a check in you callback function.

function my_trash_action( $post_id ) {
   if ( 'custom_post_type' != get_post_type( $post_id )
       return;
     //Do Stuff....
}
add_action( 'trashed_post', 'my_trash_action' );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *