I want to update/delete a post meta when a custom post (in this case custom post type is "booking") is updated upon the change of post meta . In my case if user change the post meta booking_status to 'denied' and then update the post, then I want to delete the post_meta booking_status immediately .

Here is what I have tried

add_action( 'save_post', 'booking_status_is_updated' );

function booking_status_is_updated(){
   global $post;
   if($post->post_type =='booking'){



But this is not working ? How can I get it done ?

  • Well, first use the hook properly. The post ID will be passed in. You don't need $post->ID.
  • Second, use the correct hook. If you want to run save_post only for your booking type, use save_post_booking

But otherwise, the code works. I just ran a quick test.

function booking_status_is_updated($post_id){

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.