php - Wordpress rest api, update info
I have custom post 'note' and the route to update the content of the particular note:
register_rest_route( 'university/v1', 'note/(?P<id>\d+)', array(
'methods' => 'POST',
'callback' => 'uni1UpdateNote',
) );
function uni1UpdateNote($data){
return $data['title']; // $data['title'] returns null, $data returns {}
}
and my js file:
let data = {
'title': noteBlock.find('.note-title').html(),
'content': noteBlock.find('.note-content').html(),
};
$.ajax({
beforeSend: (xhr) => {
xhr.setRequestHeader('X-WP-Nonce', uni1NoteData.nonce)
},
url: uni1NoteData.urlRoot+'/wp-json/university/v1/note/'+getID(),
type: 'POST',
data: data,
success: function(response) {
console.log(response);
},
error: function(response){
console.log(response);
}
});
As I understand the route's callback function gets parameters $data from javascript file. How to check what is in $data variable? I use postman, but I get null or empty object. What am I doing wrong? I just want to update my note.