custom post types – meta data disappearing
-
Hi folks,
I’m experiencing some odd behaviour from the custom field data in a custom post type I’ve created.
I’ve asked for help on the IRC channel so if a solution is found there before it is here I’ll post it for anyone else who might run into this scenario.
Basically I’ve set up a custom post type and added some meta data fields to the add/edit page for that post type.
To begin with, I add a new post to it and it appears to keep the data.
I reload the page (not resubmitting, just hitting return in the address bar) and the data is still there.
I load up the front end of the site and the data appears where i want it.
So far so good.
I then go to the list of posts in the backend, click on the post I made and notice that the fields are now empty or back to their default value.
Has anybody experienced anything like this before?
You can view the code I’ve used to create the custom field and add the meta data boxes to the page here.
If anybody can help it’d be great because I’m stumped!
Cheers,
Robert
-
*bump*
I found this but I have no idea how to go about implementing it with the code I’ve got just now.
Anybody have any ideas?
Cheers,
RobertFor whoever deleted my bump.
Thanks a lot. I’m just here trying to get some help in a forum which seems to get hundreds of posts every 10 minutes and nobody looks at threads past page 1 unless they’ve already made a post on it.
Again, thanks a lot, I REALLY appreciate it. >:|
Hi Rab,
I had a similar problem (also my post here has been unanswered) and was scratching my head for ages until I found your post. I looked at your code on the site that you linked, and it seems to solve my problem. Basically from what I can see you need to add
if ((!$post_id) || (!isset($_POST['custom_data'])) || ($post->post_type != 'posttype')) return $post;to the beginning your save function which starts on line 43. Essentially before you start saving any custom fields, if the data is missing, then abort abort abort (return #post).
Of course, don’t forget to replace “posttype” in my example with the name of YOUR custom post type. The code in the link you supplied is for ‘post’… my custom type is for ‘book’, so that’s what I have there. Also “custom_data” should be the name of one of your custom metal fields.
Good luck!
I realize this is a bit late, but I was having the same issue and this very simple fix posted by Andrew Gail worked for me:
http://www.andrewgail.com/wordpress-autosave-and-custom-fields/
I thought I’d post it here in case some one facing a similar issue finds this thread.
The topic ‘custom post types – meta data disappearing’ is closed to new replies.