0

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

1
  • Please use the code styling and links - we'll approve your edit in mins. Thanks.
    – kaiser
    Jul 3, 2012 at 16:09

1 Answer 1

0

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;
}
3
  • Is add_action to this wp_trash_post() hook, is it work when we use wp_delete_post() ? Jul 13, 2012 at 22:20
  • No, you'll also need to use before_delete_post (pre) or deleted_post (post) to listen out for deletions. Jul 13, 2012 at 23:03
  • wp_trash_post only seems to work on posts, not on pages or CPTs
    – urok93
    Sep 3, 2012 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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