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 }
})
Related Posts:
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- WordPress Rest API
- var is undefined in a Gutenberg block
- Script Localization doesn’t work
- Search for a keyword across post types in a Gutenberg component
- Check if user can in javascript
- wp-api Backbone JS Client fetch options
- How should I identify the inline javascript that is the dependent of a wp_enqueue_script?
- Combining results from WP-API using AngularJS
- How to make a discord bot create an invite for every server it joins?
- How do I run code I have written in JavaScript?
- Error: Can’t set headers after they are sent to the client
- Array.size() vs Array.length
- Pure JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]
- Get String in YYYYMMDD format from JS date object?
- How to pop an alert message box using PHP?
- TypeError: Router.use() requires middleware function but got a Object
- Chart.js Bar graph will not start at zero as minimum value
- Cannot GET / Nodejs Error
- Uncaught SyntaxError: Unexpected token u in JSON at position 0
- Node.js – SyntaxError: Unexpected token import
- Setting “checked” for a checkbox with jQuery
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- How to test valid UUID/GUID?
- Angular: Error no directive with “exportAs” set to “ngForm”
- How can I remove a character from a string using JavaScript?
- Setting onSubmit in React.js
- jQuery Ajax File Upload
- Merge/flatten an array of arrays
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- How to implement authenticated routes in React Router 4?
- How to create a JQuery Clock / Timer
- Access Control Request Headers, is added to header in AJAX request with jQuery
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- How to check if function exists in JavaScript?
- ActiveXObject is not defined and can’t find variable: ActiveXObject
- setInterval in a React app
- How do I declare a namespace in JavaScript?
- Remove duplicate values from JS array
- Trying to convert crmForm to Xrm.Page
- Encode HTML entities in JavaScript
- getBoundingClientRect is not a function
- Jquery button click() function is not working
- Make iframe automatically adjust height according to the contents without using scrollbar?
- Uncaught ReferenceError: function is not defined with onclick
- Remove last item from array
- Uncaught ReferenceError: define is not defined typescript
- How do I check whether a checkbox is checked in jQuery?
- Failed to find a valid digest in the ‘integrity’ attribute for resource on a deployed emberjs application
- Cannot read property ‘getHostNode’ of null
- TypeError: Class extends value undefined is not a function or null
- Eslint: How to disable “unexpected console statement” in Node.js?
- How to get native javascript functions source code?
- jQuery count child elements
- javascript check for not null
- Get the Highlighted/Selected text
- Video auto play is not working in Safari and Chrome desktop browser
- Replace all spaces in a string with ‘+’
- How to get the children of the $(this) selector?
- JavaScript array to CSV
- Uncaught ReferenceError: ga is not defined
- Getting or changing CSS class property with Javascript using DOM style
- How to close a window using jQuery
- Javascript- Multiplying 2 numbers and return number
- What does the $() function do in JavaScript?
- How to change href of tag on button click through javascript
- parsing JSONP $http.jsonp() response in angular.js
- WP Rest API – How to get featured image
- wp_add_inline_script without dependency
- How to configure WordPress to be able to use tag inside posts?
- How to only enqueue block javascript on the frontend when its needed [duplicate]
- Correct place to register and enqueue scripts
- How to add JS in footer
- Disable unneeded scripts in a wordpress installation
- Restrict file types in the uploader of a wp.media frame
- How can I get the standard WP-Editor through Javascript?
- Gutenberg getMedia() in post query doesn’t return all featured images
- Can I change an external script’s HTML?
- How to transform a legacy widget into a block
- Gutenberg select categories
- const { __ } not working in IE11
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- AJAX not Working with php as supposed
- Performance vs plugin genrated javascript
- Cannot use characters ” in jQuery script in WordPress
- How to install cool javascript feature in WordPress?
- How can I load certain JavaScripts only on blog pages?
- jQuery UI Tools (Flowplayer) Issues
- How can I leverage browser cache for minified JS or minified CS files?
- Normal for scripts to be loaded after body tag?
- Close modal window after form submit [closed]
- Form will not popup, when clicking on the link to the form
- JS inside modal doesn’t work
- How to Get Post Meta in .Js File [duplicate]
- internal anchor links no longer working after upgrade
- How do you change the text “Update failed. You are probably offline.”
- The page isn’t redirecting properly was given when redirecting
- JavaScript problem in a WordPress PAGE
- I keep getting Javascript error messages
- Use add_action to run a script, but only on the post editor page