Using update_post_meta() to update an array

Are you trying to use update_post_meta() in order to try update post meta which is stored within an array? Here’s a quick guide on how to do this.

Update post meta stored within an array

If you’re trying to update your post meta, which is stored within an array, all you need to do is store your array within a temporary variable and edit the contents accordingly

$temp_array = get_post_meta( get_the_ID(), 'your_meta_key', true );
$temp_array['your_sub_meta_key']['your_sub_sub_meta_key'] = 'New value here';
update_post_meta( get_the_ID(), 'your_meta_key', $temp_array );

Note, the true within the get_post_meta() function is extremely important to maintain here, in order to update the right dimension of your array.

If you’re trying to run this programmatically, please see the example used within this answer.