Importing from XML is ignoring serialized custom field

I have been trying to import something into a custom field using the WordPress Import tool but it seems to be leaving the custom field empty in the database.

<wp:meta_value><![CDATA[a:19:{s:7:"address";s:50:"52, St. Michaels Rd,Sheffield,S359YN";s:11:"gpsLatitude";s:18:"";s:12:"gpsLongitude";s:18:"";s:18:"streetViewLatitude";s:9:"";s:19:"streetViewLongitude";s:18:"";s:17:"streetViewHeading";s:17:"";s:15:"streetViewPitch";s:18:"";s:14:"streetViewZoom";s:1:"0";s:9:"telephone";s:13:"01142570288";s:5:"email";s:19:"";s:3:"web";s:17:"";s:11:"hoursMonday";s:9:"";s:12:"hoursTuesday";s:9:"";s:14:"hoursWednesday";s:9:"";s:13:"hoursThursday";s:9:"";s:11:"hoursFriday";s:9:"";s:13:"hoursSaturday";s:6:"";s:11:"hoursSunday";s:6:"";s:18:"alternativeContent";s:0:"";}]]></wp:meta_value>

There doesn’t seem to be anything massive sticking out with this, but when I use the importer tool it ignores this and leaves an empty space in the database.

Read More

Any ideas of what’s happening or if there’s something blatantly obvious that’s missing?

Related posts

Leave a Reply

1 comment

  1. I have recently had a lesson in serialized arrays from a friend and it all makes sense now!
    After working this out it finally worked on the import.

    Take this for example:
    a:1:{s:7:”address”;s:50:”52, St. Michaels Rd,Sheffield,S359YN”;}

    • a:1: This is the array size, there is one piece of information in this array hense the 1.
    • a:size:{key definition;value definition;(repeated per element)}

    • s:7:”address”; This is the the size of the value. So for address there are 7 characters in the word address so the value size is 7.

    • s:size:value;

    • There is also integer values shown like this:

      • i:value;
    • Bolean values are shown like this:

      • b:value; (does not store “true” or “false”, does store ‘1’ or ‘0’)

    that’s all there basically is in a serialized array to worry about, and when correct the wordpress importer will import these into the database with no problems, but if they are wrong then it escapes itself and leaves the field in the database row empty.

    Examples:

    String
     s:size:value;
    
     Integer
     i:value;
    
     Boolean
     b:value; (does not store "true" or "false", does store '1' or '0')
    
     Null
     N;
    
     Array
     a:size:{key definition;value definition;(repeated per element)}
    
     Object
     O:strlen(object name):object name:object size:{s:strlen(property name):property name:property definition;(repeated per property)}
    
     String values are always in double quotes
     Array keys are always integers or strings
        "null => 'value'" equates to 's:0:"";s:5:"value";',
        "true => 'value'" equates to 'i:1;s:5:"value";',
        "false => 'value'" equates to 'i:0;s:5:"value";',
        "array(whatever the contents) => 'value'" equates to an "illegal offset type" warning because you can't use an
        array as a key; however, if you use a variable containing an array as a key, it will equate to 's:5:"Array";s:5:"value";',
         and
        attempting to use an object as a key will result in the same behavior as using an array will.