Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question
    
I'm not sure if the WP Importer plugin really does import custom meta data. Do you have a proof that it has this functionality? –  kaiser Feb 25 '13 at 18:57
    
I can import from another xml file and it imports this data okay, but with this it just leaves an empty row in the database which is where im thinking there is something wrong with that line –  Oliver Whysall Feb 25 '13 at 19:09
    
I have just been told that the length values were a miss match which is what was causing the issue! I knew it was something stupid! –  Oliver Whysall Feb 25 '13 at 19:44
    
The import tool has several weaknesses (doesn't import menu item meta either). I use full database dumps when I can. –  helgatheviking Feb 25 '13 at 19:56
    
@OliverWhysall PLEASE post this as answer and mark it as solution in two days. Thanks. –  kaiser Feb 25 '13 at 20:02
add comment

1 Answer 1

up vote 1 down vote accepted

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.
share|improve this answer
    
The data is usually wrong because of line-endings. A very annoying problem. –  WraithKenny Jun 25 at 19:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.