Updata Metadata WP Rest API

Two things need to be changed

1 – wishlistPost.metadata.wishlist_array which is the metadata returns an object with a string inside, not an array.

var wishlist_array = wishlistPost.metadata.wishlist_array[0]; //Get current string

          wishlist_array += postID + ","; //Concat new ID to the current string

2 – JSON.stringify(wishlist_array) is not needed as stated above wishlist_array is a string already. As Sally CJ commented the body should be as follow:

body: JSON.stringify({
              metadata: { wishlist_array: wishlist_array }
            })

Leave a Comment