Update Instead of Rewriting Meta Value

Question

I have repeatable fields inside post Post Type and the meta_value is a JSON Object once post saved. I was wondering if there is a way instead of rewriting the whole JSON, to only update the changed custom fields values.

My Save function

function save_custom_meta_box($post_id, $post, $update)
{
    if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
        return $post_id;

    if(!current_user_can("edit_post", $post_id))
        return $post_id;

    if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
        return $post_id;

    $slug = "post";
    if($slug != $post->post_type)
        return $post_id;

    $meta_box_text_value = "";
        if(isset($_POST["meta-box-text"]))
        {
            $meta_box_text_value = $_POST["meta-box-text"];
        }   
        update_post_meta($post_id, "meta-box-text", $meta_box_text_value);
}
add_action("save_post", "save_custom_meta_box", 10, 3);
0
, , trunks 7 months 0 Answers 105 views 0

Leave an answer