WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a plugin that has multiple meta boxes. One meta box saves a single record by using update_post_meta(). Another meta box saves multiple record by using add_post_meta().

I do not have revisions turned on in the post_type.

How would you delete_post_meta() a single specific record in the meta box that uses add_post_meta()? Best practice advise is needed.

If you're going to send the whole $post->ID and it will get the array of records, how can I detect the specific meta_key set to be deleted?

Here is the code on github: https://github.com/fritzdenim/stec-events/blob/62d5c641622f75a610da09462260f09713f0abab/index.php

share|improve this question
up vote 1 down vote accepted

I'd say there is barely enough information in the question to speculate on an answer but it sounds like to me that...

If your data is saved in individual key/value pairs then delete_post_meta will do it. You would pass the function a post ID and a key name: delete_post_meta(1,'keyname');. It will delete the whole key/value pair.

If you have multiple bits of information saved as a serialized array/object then delete_post_meta will not work. You will need to pull the data for the key you want with get_post_meta, alter the array/object in PHP to remove the key/value you want to delete, and then save the altered data with update_post_meta.


share|improve this answer
Where would the delete_post_meta() get the $post_id from? I'll place the code anyway... just a sec. – Franz Noel Jun 28 '13 at 17:43
Your description makes me think delete_post_meta won't work, but the short answer to that question is that you have to give the post ID to the function. – s_ha_dum Jun 28 '13 at 17:44
If you're going to send the whole $post->ID and it will get the array of records, how can I detect the specific meta_key set to be deleted? – Franz Noel Jun 28 '13 at 17:58
You also give delete_post_meta a key but take a careful look at the answer. delete_post_meta will delete the entire key. That is why I said delete_post_meta will not work. You need to pull the data, process it in PHP and then put the data back. – s_ha_dum Jun 28 '13 at 18:07
I tried this and it does not work because there are 2 hooks for publish_post and save_post. Maybe this will work in a json setting where you update one field. – Franz Noel Jun 28 '13 at 21:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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