Deleting all post meta on import
-
Hello,
I am trying to import some post meta for a custom “State” field using the importer. The posts already exist as well as the ‘list-state’ meta_key, however it is empty in the database.
My CSV looks like this:
“post_type”,”post_id”,”list-state”
“hut”,2913,”Radovljica”
“hut”,2914,”Tolmin”
“hut”,2915,”Mozirje”When I import the above CSV I see:
Processing “” Done.
Processing “” Done.
Processing “” Done.Which doesn’t seem right to begin with. However after the import the new meta_value has not been added to ‘list-state’. In fact an investigation of the database shows that ALL existing meta data for each post in the CSV has been deleted from the post_meta table and nothing new has been added. There is no longer any meta data in the post_meta table with the ID’s 2913, 2914 and 2915 etc. It has all been erased.
Of course I need to import data for a lot more than 3 items and I don’t want to erase all of my existing post meta.
What am I doing wrong?
Thanks,
Nicole
-
I tested with similar data below, but any post meta values were not deleted.
“post_type”,”post_id”,”list-state”
“post”,72,”Radovljica”
“post”,73,”Tolmin”
“post”,74,”Mozirje”Could you send me or upload your actual csv file?
Certainly I can send the whole file, however that is all the content within the actual CSV file. A CSV with exactly that content and nothing else is deleting all meta data for those posts. There were more lines in my csv but I removed them as I was inadvertently deleting a lot of metadata and I have to restore my database after every test. Luckily I have a backup.
How can I send the file to you? I cannot see a way to attach a file on here or to message you privately?
Can I email you?
Thanks,
NicolePlease send to hishikawa@notnil-creative.com
I’ve tested with the data which you send me, but post meta data were not deleted. I’m sorry, but I can’t reproduce the error.
Thank you very much for that.
There must be a clash with another plugin or something. I will do some further testing and post my findings here.
Nicole
Ok after a thorough investigation I have tracked this issue down to a clash with another plugin. The one which is responsible for the custom post type “hut”. I cannot simply disable this plugin to import my csv as then the custom post type “hut” does not exist.
We have a function which resembles this:
add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2); function wp_insert_post($post_id, $post = null) { if ($post->post_type == "hut") { foreach ($this->meta_fields as $key) { $value = @$_POST[$key]; if (empty($value)) { //Below is the troublesome line which deletes all post meta. delete_post_meta($post_id, $key); continue; } //More code here that is not relevant. } }
This function is clearly being executed when the CSV import is being performed and consequently it is deleting all the post meta.
I don’t want to edit your plugin code so do you have any ideas how I could change the above code so that it is not activated when your csv plugin runs?
Thank you very much,
NicoleI can’t understand why that plugin deletes all post meta data. Weird.
- The topic ‘Deleting all post meta on import’ is closed to new replies.