I have a Custom Post Type "empresa" and would like to send email when a post type is deleted (moved to trash).

I have this function below for my POSTS, How can I use with my Post Type "empresa"?

add_action("trash_post", "my_awesome_publication_notification");
function my_awesome_publication_notification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);

$author_email = get_post_meta( $post->ID , 'empresa_contato_email' , true );
$email_subject = "A Sua Empresa foi aprovada!";




    Hi, <?php echo $author->display_name ?>. I've just published one of your articles
    (<?php echo $post->post_title ?>) on MyAwesomeWebsite!

    If you'd like to take a look, <a href="<?php echo get_permalink($post->ID) ?>">click here</a>.
    I would appreciate it if you could come back now and again to respond to some comments.



$message = ob_get_contents();


wp_mail($author_email, $email_subject, $message);


  • That should work fine with your custom post type. Does it not? Nov 6 '11 at 15:32
  • Hi, it is working just with POSTS not the "Empresa" Custom Post Type.
    – Raoni
    Nov 8 '11 at 15:23
  • I triyed "trash_empresa" but does not work....any clue?
    – Raoni
    Nov 8 '11 at 15:23
  • Actually, that hook gets fired regardless of post type. Look at the code. If you defined EMPTY_TRASH_DAYS in your site's wp-config.php and it's set to 0 or false, the hook will never fire -- the post just gets deleted. Nov 8 '11 at 16:58

Use wp_trash_post instead, and keep in mind {post_status}_{post_type} so originally it should have been trash_empresa not trash_post, try wp_trash_empresa too


For any future readers it seems the hook has now changed from 'trash_post' to 'wp_trash_post' trac ticket explaining the name change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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