Create action running on trashed_post hook to modify post_meta value

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. ;)

Topic trash post-meta actions hooks custom-post-types Wordpress

Category Web


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';
    wp_insert_post($post);

    wp_trash_post_comments($post_id);

    do_action('trashed_post', $post_id);

    return $post;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.