post values to custom post type which has advanced custom fields
Question
I am trying to use Ajax and jQuery to post data to a custom post type. The title field works as is standard wordpress field but the color field does not. I also tried replacing ‘color’ with the name of the ACF itself like ‘field_5ec63bc5b6fe0’ but that also does not work.
$('.submit-color').on('click', function (e) {
e.preventDefault();
var newColor = {
'title': $( '.title' ).val(),
'color': $( '.color' ).val(),
'status': 'private'
}
$.ajax({
url: myData.root_url + '/wp-json/wp/v2/color/',
type: 'POST',
data: newColor,
beforeSend: (xhr) => {
xhr.setRequestHeader('X-WP-Nonce', myData.nonce);
}
})
.done(function (data) {
console.log(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus + ': ' + errorThrown);
console.warn(jqXHR.responseText);
});
})
0
advanced-custom-fields, ajax, rest-api, wp-api
4 years
2020-05-21T05:11:57-05:00
2020-05-21T05:11:57-05:00 0 Answers
75 views
0
Leave an answer