Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
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

if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )

Any help would be much appreciated, Thanks, Ashley

share|improve this question

2 Answers 2

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);

to

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

worked in my case.

share|improve this answer
up vote 0 down vote accepted
if(isset($_POST["testimonyname"]))

Placing this code before the update_post_meta lines worked perfectly.

share|improve this answer

Your Answer

 
discard

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.