WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Importer
[resolved] Missing Serialized Meta Value (8 posts)

  1. Valentin
    Member
    Posted 2 years ago #

    Hi,

    The importer worked just fine, but it missed a custom theme's (custom post type) meta key value that is stored as an PHP array (serialized by WordPress).

    Here's the XML file:

    <wp:postmeta>
    			<wp:meta_key>_custom_info</wp:meta_key>
    			<wp:meta_value><![CDATA[a:20:{s:6:"data";...more data...;}]]></wp:meta_value>
    		</wp:postmeta>

    After I imported the file, in the database the '_custom_info' meta_value was empty.

    All other custom fields that containted only numbers are fine.

    Now when I looked at the XML file again I see that a meta key '_menu_item_classes' is also serialized, but it's fine in the database.

    Here is my array that is being stored as a custom field:

    array
      's1' => string '1' (length=1)
      's2' => string '123' (length=3)
      's3' =>
        array
          'asd1' => string 'sss' (length=3)
          'asd2' => string 'sss' (length=3)
          'asd3' => string 'sss' (length=3)
          'asd4' => string 'sss' (length=3)
          'asd5' => string 'sss' (length=3)
          'asd6' => string 'sss' (length=3)
      's4' => string 'sss' (length=3)

    http://wordpress.org/extend/plugins/wordpress-importer/

  2. Jon Cave
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    I just tested it with the following post meta:

    <wp:postmeta>
      <wp:meta_key>_custom_meta</wp:meta_key>
      <wp:meta_value><![CDATA[a:4:{s:5:"keyed";s:4:"with";s:7:"strings";s:3:"not";s:4:"with";s:6:"digits";s:4:"look";a:2:{i:0;s:8:"subarray";i:1;s:2:"yo";}}]]></wp:meta_value>
    </wp:postmeta>

    and it all worked fine. Automated tests also exist which test serialized meta being imported, so I don't think it's caused by the serialization alone.

    Could you paste some unedited post meta that didn't import? If a lot of text then use a pastebin like pastie.org.

    Are you using the latest version of the importer (0.5.2 at time of writing)?

  3. Valentin
    Member
    Posted 2 years ago #

    Yes, I have the latest version of the importer.

    http://pastebin.com/0FSBNhet

  4. Jon Cave
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    The importer attempts to use two different XML parsers included in PHP, but has a fallback to a regular expression based parser (yuck!). I tracked the issue down to this regex parser doing something funny to serialized values, but I'm not sure exactly why yet as it only seems to affect some meta values as you noticed. I'll try to get a fix out soon.

    Thanks for the report :)

  5. Jon Cave
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    If you change line 469 of wordpress-importer/parsers.php from

    $return = $wpdb->escape( trim( $return ) );

    to

    $return = trim( $return );

    i.e. remove the call to $wpdb->escape(). It should work for you. The entire line can probably be commented out too.

  6. Valentin
    Member
    Posted 2 years ago #

    Thanks for the fix!

    Any idea when the fix will be added to the offical release?

  7. Jon Cave
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    No problem. Probably tomorrow if not later today.

  8. marikamitsos
    Member
    Posted 2 years ago #

    Hello Jon

    Jon Cave | Administrator | Posted 1 week ago #
    No problem. Probably tomorrow if not later today.

    I just updated to v.0.5.2 but the fix is NOT there.
    Is it because it doesn't work that well and needs further testing?
    Should we also do this change as well(we have custom posts too)?

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic