WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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?

share|improve this question

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 )
     //Do Stuff....
add_action( 'trashed_post', 'my_trash_action' );
share|improve this answer
So in my function then how can I check that my custom post type was deleted, not any other post type? – drtanz Sep 3 '12 at 10:42
Also can I use the hook trash_my_cpt that would fire only for my custom post type? Reference codex.wordpress.org/Post_Status_Transitions and github.com/WordPress/WordPress/blob/master/wp-includes/… – drtanz Sep 4 '12 at 11:52
I think you can use wp_trash_mycpt – drtanz Mar 15 '13 at 12:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.