0

I am trying to store metabox data as json in wordpress and then get it using wp-json api.

What i tried

$current = array(
  'id' => "in json object",
  'name' => 'name in json object'
);
$serializedArray = unserialize($current);
update_post_meta($post_id, 'ha_basic_information', serialize($current));

What i am trying to achieve {"id": "in json object", "name": "name in json object"}

What i am getting "s:75:\"a:2:{s:2:\"id\";s:14:\"in json object\";s:4:\"name\";s:19:\"name in json object\";}\";"

I want to get data as object in wp-json api. I've tried serialize/unserialize, json_encode/json_decode but nothing seems to work. I am new in php and can't figure it out. there are many questions related to this but nothing seems to work.

  • Don't encode or serialize it at all. WordPress will handle that. Just use update_post_meta( $post_id, 'ha_basic_information', $current ); – Jacob Peattie May 23 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.