Instead of rubber ducking, I’m writing it out here…

I’m trying to modify @benbalter’s WordPress Jekyll Export plugin to extract serialzed data from post_meta values. It seems most (all?) of the IndieWeb WordPress plugins use serialized values so it’s necessary to migrate. Otherwise I wind up with YAML that looks like this

  - 'a:1:{i:0;s:52:"";}'
  - 'a:2:{s:4:"icon";s:4:"none";s:10:"visibility";s:6:"public";}

The chunk of code that handles that

// Convert traditional post_meta values, hide hidden values.
        foreach ( get_post_custom( $post->ID ) as $key => $value ) {

            if ( substr( $key, 0, 1 ) === '_' ) {

            $output[ $key ] = $value;


What I need to do is unserialize $value and if it’s an array, loop through them and nest the values for each $key.

to get something like


    - icon: none
       visibility: public

But my first step is to unravel the serialized $value. I’ve tried just adding $output[ $key ] = maybe_unserialize ($value ); and that didn’t work like the magic bullet I’d hoped.


Got Something To Say?

Your email address will not be published. Required fields are marked *