0

Question: Is it possible to update the meta box value of a WordPress post using some function like we do with update_post_meta()?

Explanation: Here is the format of the data saved in database for the metabox I want to update with a function/hook. enter image description here

Now, if I want to update just a single entry from that data, let say 'start_year' then how can I do that using a function/hook?

If I choose to go with update_post_meta(65, '_mycpt_date', ''2010), it will obviously replace everything with just '2010'.

Community
  • 1
  • 1
Awais Umar
  • 2,027
  • 3
  • 27
  • 46

1 Answers1

1

After doing a bit of brainstorming and with the help of this I did it with a little bit of workaround.

// Storing the value/array in the variable.
   $options = get_post_meta( 65, '_chronos_date', true);

// Updating the new value using key-value pair. That way, other parts of the array would remain un-touched.
  $options['start_year']= "2000";

// Update the new value.
update_post_meta(65,'_chronos_date',$options);

It was quick. I hope it'd help someone else.

Community
  • 1
  • 1
Awais Umar
  • 2,027
  • 3
  • 27
  • 46