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 have a custom post type that always do math operation to its post_meta and other custom post type post_meta.

For example:

  • post-type 1 = cpt_product_order
  • post-type 1 post_meta = cpt_pm_product_order
  • post-type 2 = cpt_product
  • post-type 2 post_meta = cpt_pm_product_stock

There's a cpt_product with cpt_pm_product_stock = 100, frontend operation enable specific user made order by inserting new cpt_product with post_meta cpt_product_order of 10 will substract cpt_pm_product_stock to 90

100 cpt_pm_product_stock - 10 cpt_product_order = 90 cpt_pm_product_stock

cancelling order will delete/trash the cpt_product and cpt_product_order, and cpt_pm_product_stock should back to 100.

Which action hook should used for this operation? Is it trashed_post?

I didn't find any answer on codex, http://codex.wordpress.org/Plugin_API/Action_Reference/trashed_post is empty

Thanks in advance for an answer. ;)

share|improve this question
Please use the code styling and links - we'll approve your edit in mins. Thanks. – kaiser Jul 3 '12 at 16:09

wp_trash_post and trashed_post - from source:

function wp_trash_post($post_id = 0) {
    if ( !EMPTY_TRASH_DAYS )
        return wp_delete_post($post_id, true);

    if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
        return $post;

    if ( $post['post_status'] == 'trash' )
        return false;

    do_action('wp_trash_post', $post_id);

    add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
    add_post_meta($post_id,'_wp_trash_meta_time', time());

    $post['post_status'] = 'trash';


    do_action('trashed_post', $post_id);

    return $post;
share|improve this answer
Is add_action to this wp_trash_post() hook, is it work when we use wp_delete_post() ? – Ivan Slaughter Jul 13 '12 at 22:20
No, you'll also need to use before_delete_post (pre) or deleted_post (post) to listen out for deletions. – TheDeadMedic Jul 13 '12 at 23:03
wp_trash_post only seems to work on posts, not on pages or CPTs – drtanz Sep 3 '12 at 10:18

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.