0

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.

1 Answer 1

0

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;
2
  • 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. Commented Jun 17, 2012 at 9:26
  • Do you ever add the 'admin_init' function to a hook? Commented Jun 19, 2012 at 22:58

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.