ThemeForest

Custom Fields not saving/updating

1841 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
digitalimpact says

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 ! :)

2 years ago
10 posts
  • Has been a member for 3-4 years
  • Bought between 100 and 499 items
webdezyner says

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…

2 years ago
1841 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
digitalimpact says

Thanks for replying :)

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?

2 years ago
10 posts
  • Has been a member for 3-4 years
  • Bought between 100 and 499 items
webdezyner says

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.

2 years ago
1841 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
digitalimpact says
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 ;)

2 years ago
2698 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Forum Superstar
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 50 and 99 users
duotive says

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

2 years ago
by
by
by
by
by