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

2 Answers 2


Placing this code before the update_post_meta lines worked perfectly.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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