i am getting meta data from wordpress to angularjs application using wordpress rest api. how can i unserialize wordpress meta data unserialize before leave from server. meta data is like this :
["a:29:{s:8:\"subtitle\";s:14:\"iphone Showroom\";s:12:\"featuredItem\";s:1:\"0\";s:10:\"headerType\";s:3:\"map\";s:11:\"headerImage\";s:0:\"\";s:12:\"headerHeight\";s:0:\"\";s:3:\"map\";a:7:{s:7:\"address\";s:23:\"Mod city\";s:8:\"latitude\";s:13:\"26.4819543403\";s:9:\"longitude\";s:13:\"76.7334592342\";s:10:\"streetview\";s:1:\"0\";s:9:\"swheading\";s:2:\"90\";s:7:\"swpitch\";s:1:\"5\";s:6:\"swzoom\";s:1:\"1\";}s:9:\"telephone\";s:12:\"074002344777\";s:19:\"telephoneAdditional\";s:0:\"\";s:5:\"email\";s:26:\"[email protected]\";s:9:\"showEmail\";s:1:\"1\";s:15:\"contactOwnerBtn\";s:1:\"1\";s:3:\"web\";s:0:\"\";s:12:\"webLinkLabel\";s:0:\"\";s:19:\"displayOpeningHours\";s:1:\"1\";s:18:\"openingHoursMonday\";s:19:\"09:00 AM - 08:00 PM\";s:19:\"openingHoursTuesday\";s:19:\"09:00 AM - 08:00 PM\";s:21:\"openingHoursWednesday\";s:19:\"09:00 AM - 08:00 PM\";s:20:\"openingHoursThursday\";s:19:\"09:00 AM - 08:00 PM\";s:18:\"openingHoursFriday\";s:19:\"09:00 AM - 08:00 PM\";s:20:\"openingHoursSaturday\";s:19:\"09:00 AM - 08:00 PM\";s:18:\"openingHoursSunday\";s:19:\"09:00 AM - 08:00 PM\";s:16:\"openingHoursNote\";s:0:\"\";s:18:\"displaySocialIcons\";s:1:\"0\";s:26:\"socialIconsOpenInNewWindow\";s:1:\"0\";s:11:\"socialIcons\";s:0:\"\";s:14:\"displayGallery\";s:1:\"1\";s:7:\"gallery\";a:2:{i:0;a:2:{s:5:\"title\";s:0:\"\";s:5:\"image\";s:68:\"http://www.example.com/wp-content/uploads/2017/02/DSCN0366-min.jpg\";}i:1;a:2:{s:5:\"title\";s:0:\"\";s:5:\"image\";s:68:\"http://www.example.com/wp-content/uploads/2017/02/DSCN0365-min.jpg\";}}s:15:\"displayFeatures\";s:1:\"0\";s:8:\"features\";s:0:\"\";}"]
i have done some research and found the solution. we have to do this on server side like this. you should edit your function.php and use the code like this
add_action( 'rest_api_init', 'create_api_custom_meta_field' );
function create_api_custom_meta_field() {
register_rest_field( 'custom-post', 'post_all_meta_fields', array(
'get_callback' => 'get_post_meta_for_api',
'schema' => null,
));
}
function get_post_meta_for_api( $object ) {
//get the id of the post object array
$post_id = $object['id'];
//return the post meta
return get_post_meta( $post_id );
}
after this code you will get all serialize meta data in json object. :)