Wordpress - How to extract data from a post meta serialized array?

Use unserialize() to convert it into an array.

$mydata = 'a:5:{s:9:"engine_id";a:1:{i:0;s:9:"300000225";}s:15:"transmission_id";a:1:{i:0;s:6:"257691";}s:5:"plant";a:1:{i:0;s:23:"Oshawa, Ontario, Canada";}s:15:"Manufactured in";a:1:{i:0;s:6:"CANADA";}s:22:"Production Seq. Number";a:1:{i:0;s:6:"151411";}}';
$mydata = unserialize($mydata);
echo $mydata['Manufactured in'][0];

Edit- Related thought- something to keep in mind when storing meta data serialized like this is that you limit your ability to use that data in queries, if that's a concern for you. for instance, it's not so easy to write queries like "show me all parts manufactured in Canada", or order results by engine id, since that data is tucked away with a bunch of other data in one field.


You can use this WordPress codex which converts into an array.

maybe_unserialize($data);

https://developer.wordpress.org/reference/functions/maybe_unserialize/