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!
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;
}
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
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
There is a problem with them, however, as I found out here.
Thanks for taking the time to help though, much appreciated