Custom Fields not saving/updating


#1

Hey guys,

Another call for help with WP (3.01)…

I’m using this tutorial to add meta boxes to custom post type edit page:
http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html

I have 4 custom post types so, in functions.php, I require_once one PHP file with functions for each of them. In each of those files I do the metaboxes like in the tut.

Everything is working great, except one custom field - whatever I do, it doesn’t save the data when publishing/updating a post

At first, I thought it was because naming (mnt_supteren) was similar to another one (mnt_sup), as in they both started with ‘sup’ - but I see that’s not it, since I’ve given them unique names and it persists…

I can only manually select a custom field key and add a value to it, without updating the page (won’t work like that).

Thing is, this is for a client and I don’t want him to use the custom fields box (he’d get lost with all those prefixes and stuff there…)

Measures I took:

  • custom fields are not named the same
  • I have no blank lines in functions.php or any of the files I require in it

Have you experienced custom fields not saving/updating?

Any help is greatly appreciated, this is driving me NUTS! :slight_smile:


#2

You’re likely experiencing an issue with Wordpress’s Autosave System. Custom functions aren’t passed along for autosaves.

In your “Save” function you should check if the DOING_AUTOSAVE constant is set (this seems to be preferable to checking the post action) and return something like this:

if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {
return $postID;
}

I hope this helps…


#3

Thanks for replying :slight_smile:

I’ve checked and it is set, it’s right in the tutorial:

		// check autosave
		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
			return $post_id;
		}

I figure it would have affected all custom fields if it wasn’t set, right?


#4

No problem, man.

Yes, the autosave would affect all custom fields.

Have you given all of your inputs names? I see that in the tutorial names aren’t set.


#5
Have you given all of your inputs names? I see that in the tutorial names aren't set.

Hmm, forgot about that.

However, I did solve the problem. It was because I’m an idiot, of course :slight_smile:

I was basically replicating that tutorial for each custom post type, so I had the same array declared multiple times. Same with prefix and the save data functions…

I wrapped them up nicely under one block of code, in one single file and it saves the data as it should now. I also disabled the post auto saving in WordPress, just to make sure…

I just needed a break from 6+ hours of coding to see what a childish mistake I was doing :slight_smile:

There is a problem with them, however, as I found out here.

Thanks for taking the time to help though, much appreciated :wink:


#6

i use this : http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/ and it’s lovely… ask me if you can’t figure how to add the selectbox :))