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
function save_details( $post_id ){  
if ( wp_is_post_revision( $post_id ) )
    $post_id = wp_is_post_revision( $post_id );

update_post_meta( $post_id, "testimonyname", $_POST["testimonyname"] );
add_action('save_post', 'save_details', 10, 1); 

I have a custom post type with a custom field, but after adding several i noticed that the data in the custom field was missing from some previous entries.

I filled them in again and it looked fine.

Then i clicked the Add New button just once and 1 of my posts has it's custom meta data deleted.

However, it doesn't happen every time i click Add New.

I have tried this solution but to no avail


Any help would be much appreciated, Thanks, Ashley

share|improve this question
up vote 0 down vote accepted

Placing this code before the update_post_meta lines worked perfectly.

share|improve this answer

I don't believe this will work -- at least not in all cases. This tests to see if the $_POST['some_custom_variable'] is empty, and if it is empty, it doesn't update. This is fine if the custom field will always contain a value, however you won't be able to empty the custom field's value using this code.

I was stuck with a similar problem and found changing the action call from:

add_action('save_post', 'save_details', 10, 1);


add_action('post_updated', 'save_details', 10, 1);

worked in my case.

share|improve this answer

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.