Function to execute when a post is moved to trash .

This will do the trick!

add_action('trash_post','my_trash_post_function',1,1);
function my_trash_post_function($post_id){
    if(!did_action('trash_post')){
        // do stuff
    }
}

Here we add the function, and to prevent the hook from executing more than once using did_action:

http://codex.wordpress.org/Function_Reference/did_action

As always, these kinds of hooks take the form {post_status}_{post_type}, so trash_post, trash_page, trash_customposttype, publish_page etc

Leave a Comment