Unserializing data doesn't work Unserializing data doesn't work wordpress wordpress

Unserializing data doesn't work


Whoops found the answer! :) WP function hidden in functions.php from WP themselves.

function maybe_unserialize( $original ) {    if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in        return @unserialize( $original );    return $original;}

Fixed the unserializing by doing:

$unserialized = maybe_unserialize( unserialize( $usermeta['facebookmeta'] ));

Returns it all in a neat array! :)

Happy happy! :)


You can unserialize twice:

$unserialized = unserialize( unserialize( $usermeta['facebookmeta'] ) );

NB: There's no need to serialize when using update_user_meta, it serializes automatically for you, cf. maybe_serialize: http://codex.wordpress.org/Function_Reference/maybe_serialize


I had the same problem with wp_options where custom post types have serialize data.I've figure that maybe there was a charset issue, and in fact... ta da!Try this:

$unserialized = unserialize( utf8_encode($atest[0]['option_value'] ) );

Where $atest[0] is thearray from mysql.Hope this helps!

Aisfrond