action hook save_post not working for custom post type
-
Hi everybody,
I am trying to use the action hook ‘save_post’ for a metabox within a custom post type. Using the ‘publish_post’ like this:
add_action('publish_my_custom_post_type', 'save_product_data');
works fine, but this
add_action('save_my_custom_post_type', 'save_product_data');
doesn’t. Of course I can work around this like this:
add_action('save_post', 'save_product_data'); function save_product_data(){ global $post; if ($post->post_type == 'my_custom_post_type') { update_post_meta($post->ID, '_price', $_POST['_price']); update_post_meta($post->ID, '_product_number', $_POST['_product_number']); } }
But I would really like to understand why the first hook is working but the second one isn’t. Any ideas?
Thanks a lot
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘action hook save_post not working for custom post type’ is closed to new replies.