I have used get_post_meta($post->ID) to get all custom fields for my post since I have many of htem. Some of them were checkbox values and var_dumping the variable gives me this

array (size=1) 0 => string 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";}

How do I echo those values?

I have tried var_dump(json_decode($meta['my_var'])); but it gives me null


The values look like they have been serialized using maybe_serialize( $data ).

If that's the case, then you can reverse that with maybe_unserialize( $original ).

As per this answer, unserialize( $str ) will also create a PHP value from a stored representation.


$mydata = 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";}';

$mydata = unserialize($mydata);

echo $mydata[0]; // ozujak
| improve this answer | |
  • The maybe is used in cases where you aren't quite sure. Because you know, unserialized will eventually be called. – jgraup Jan 8 '16 at 20:44

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