Support » Plugins » Hacks » import of postmeta serialized data

  • Hello everybody,

    for a current project I need to import csv data into the postmeta value field as serialized data. I don’t know how exactly the serialization works, but when I looked at existing recordsets, I realized that meta value keys (serialized inside the postmeta meta_value field) stay the same for different posts whereas the value keys change. An example:

    post 1: a:23:{s:7:”address”;s:35:”example street #1″;…}
    post 2: a:23:{s:7:”address”;s:29:”example street #2;…}

    The numbers 35 and 29 are created dynamically somehow.

    So this leads me to the question how I can import this data with a working serialization. I have no knowledge about the php/wordpress serialization algorithm. Neither if it is even wordpress internal or some logic defined by the theme I am using (it is a premium theme from Themeforest and I already contacted the support about it – without any reply so far). For that reason I want to ask here if you can give me some information on the serialization and it’s degree of dynamics that might be useful for me to achieve what I want.

    So I know that it is somehow possible to import data serialized. I mean when you insert data through the admin interface of the specific custom post type which I want to import the data into, it works. The theme authors also offer a plugin to import data to their themes which I bought. For smnall test imports it worked. But for importing a big amount of data it doesn’t. Many people are reporting the same issue about this plugin.

    In the next step I bought the WP Allimport premium plugin, which is really powerful. It supports the possibility to import serialized data, but replacing the key value part dynamically I could even not figure out with this tool so far.

    I was wondering if it is not even working dynamically but following a definition by the theme how these numbers are set for the key values of the serialized data. If I had more infos on that or which function(s) are generally used for generating serialized data from an array that could already help me to seek the import plugin’s or theme’s code.

    So you can see that I already tried a lot, spent a lot of time, thoughts and money to get the import done. Any input here from you pro’s is very welcome. I am stuck here and anything that could help me moving forward in solving this issue is very appreaciated.

    Thanks a lot in advance.

    Cheers,
    Kool

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You never want to attempt mess with or replicate the serialized format. The best approach is to convert the csv data into any array with explode() or preg_split(). Then store the array using update_post_meta(). The array will be automatically serialized when saved, and unserialized on retrieval back into an array. If you really need a serialized string to work with you could either re-serialize the array or use $wpdb to get the raw data string.

    Thread Starter Tim

    (@kool_69)

    Thank you very much for your reply bcworkz. Update_post_meta was a very useful hint. In addition I found this post and finally understood how the serialization works: http://wordpress.stackexchange.com/questions/88327/importing-from-xml-is-ignoring-serialized-custom-field

    So i imported my data via some self-defined delimiters and coded a script to split this data and update the database field via the update_post_meta() function. worked perfectly. Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘import of postmeta serialized data’ is closed to new replies.