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.

As the title says, I have a problem in functions.php (I assume it's in there) which causes custom fields to not be displayed on the new/edit post page, and when I add the meta box myself and save the data by updating the post, the data disappears.

However, if I save the data by clicking the Update button for the meta box itself (and do not click the post Update button), the data is saved and displayed properly.

I have posted the code in functions.php here.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

This has to do with auto saving. You need to check the following before saving your fields:

if ( ! isset( $_POST['action'] ) || $_POST['action'] != 'editpost' || 'revision' == $post->post_type ) 
    return;
share|improve this answer
    
Thanks, you're a lifesaver! That solved the update problem. But I still don't understand why add_meta_box(); doesn't work. The custom fields are available in the dropdown Add a custom field, but they aren't displayed automatically when you add a new post and the titles of the custom fields aren't shown either. –  Anders Norén Jun 17 '12 at 9:26
    
Do you ever add the 'admin_init' function to a hook? –  Tyler Carter Jun 19 '12 at 22:58
add comment

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.