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

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

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.