Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Delete post meta conditionally after save post

  • 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){
  if(get_post_meta($post_id,'booking_status',true)=='denied'){
    delete_post_meta($post_id,'booking_slot');
  }
}
add_action('save_post_booking','booking_status_is_updated');

Related Posts:

  1. Execute action after post is saved with all related post_meta records (data)
  2. Add post meta based on another post meta value before publish post
  3. Get updated post meta on save_post action?
  4. Correct processing of `$_POST`, following WordPress Coding Standards
  5. Set default Custom Post Meta Value
  6. Save post meta foreach loop
  7. troubles with get_post_meta (and saving it)
  8. wp_insert_post inside save_post adds wrong metadata to inserted post
  9. post_title in save_post action
  10. Auto save title as custom meta field value
  11. Save frontend submission form field as custom field
  12. get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
  13. if condition from post_meta not working in save_post
  14. Explanation of update_post_(meta/term)_cache
  15. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  16. Adding meta tag without plugin
  17. Meta compare with date (stored as string) not working
  18. How to update/insert custom field(post meta) data with wordpress REST API?
  19. Remove WordPress.org Meta link
  20. Front-end update_post_meta snippet displays white screen?
  21. How to get meta value in wp_attachment_metadata
  22. update_post_meta() not working in save_post
  23. Clean up output added via wp_head()
  24. Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
  25. Get post from meta_key and meta_value
  26. get_post_meta returns bool(false)
  27. Problem With Order Item Meta In Woocommerce
  28. Mass importing json data into custom fields (postmeta)
  29. Best way to save postmeta
  30. How to echo get_post_meta (Fluent-Framework)
  31. How to update Post Meta values through the comment system
  32. Filtering multiple meta_values
  33. get_post_meta remains empty while looping all menu items and using the ID
  34. how do I set a schedule event to modify all posts’s meta value weekly or monthly?
  35. How to stop wp_postmeta from being called on archive and search pages?
  36. How to use update_post_meta() function properly?
  37. Set the value of custom field when post is published or updated
  38. WordPress front-end media (image) upload ERROR!
  39. running function during post save and adding variable to post meta
  40. update_post_meta saves nothing in database when run in publish_post
  41. Set default value field meta_Value [closed]
  42. Can’t access post meta on new post creation (cpt)
  43. Custom post meta values reset by autosave [duplicate]
  44. Compare meta_query with a Regular Expression and do a less-than operation on it
  45. Editing does not change post_name
  46. Compare string with post id in wpdb and do stuff when match is found
  47. $wpdb class updating meta_value using Ajax [closed]
  48. Is it possible to retrieve a post and its metadata at the same time?
  49. Post meta as array looks like string instead of array
  50. How to selected which tags to print, instead of printing the whole tag list?
  51. query posts and split meta information into separate div’s
  52. add unique string as custom-field to every post
  53. How do I insert a new meta key / value pair, but only if another meta key is present?
  54. “Cannot use import statement outside a module” JS error while adding a custom meta block?
  55. Change post author without using wp_update_post()
  56. Gutenberg featured image checkbox – checkbox not correctly set on editing page reload
  57. How to properly use oneOf and anyOf in Rest Schema?
  58. Get the author meta adds now
  59. wordpress is_front_page() issue
  60. show ad after # paragraphs
  61. If ACF meta_key has meta_value
  62. How we can get “get_post_meta” of specific user who added it
  63. Repeated nav bar queries failing to be cached
  64. Randomizing Post Links Outside of Loop – No Author or Date
  65. Check for page template on save_post hook
  66. help to decipher wp metadata
  67. Insert Custom Field Value
  68. SQL query – get a featured image’s alt / alternative text
  69. I can not display meta value in extras.php and template-tags.php
  70. update_post_meta() updating nested array in Multidimensional array with empty sub-array
  71. How do I list taxonomies that have upcoming events in WP? Is there a way to do this without having to query posts first?
  72. Sorting my posts on homepage my specific value in post_meta table
  73. Strict comparisons problem when using boolean post meta
  74. Why is the actual number of thumbnail images not matching what is store in an attachments metadata?
  75. update_post_meta() is not saving the value
  76. Only show meta on one post type on search results page
  77. Check if any meta on the post has value then display content
  78. Combine meta query and give a specific meta query a higher priority
  79. I created a Custom Meta Box but it is not displaying the value on my post page
  80. Get table parameter and save in meta value
  81. How can i show post views using specified post ID?
  82. How to add/update post meta to use in query?
  83. Get post content before rendering
  84. gettext localization is not working
  85. Move Entry Meta Above Title in Archives (Genesis + Brunch Pro)
  86. Custom post type meta fields missing on save_post_type
  87. Saving post meta
  88. Multiple postmeta values to the same post_id/meta_key combination?
  89. Exclude category from DB query
  90. How to sort by meta value num, but ignore zero value?
  91. Create a Gallery and update Post Parent of Attachment Images
  92. Update event post meta each day automaticaly
  93. Advanced Custom Field — grabbing post_meta from previous post
  94. how to echo/display the custom field value in specific custom field name?
  95. How to create a link for wordpress meta datas?
  96. Fetch post meta data on POST request
  97. Which query method to use? (edit- wpdb syntax problems)
  98. How to update post meta with xml data
  99. wp_postmeta store multiple values in one key [closed]
  100. How we insert values into database using metabox WordPress?
Categories post-meta Tags post-meta, save-post
Why is it necessary to prevent direct access to included files?
Collaboratively develop a WordPress site

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress