I am trying to update a custom field for a custom post type with this function php
add_action('wp_ajax_updatemeta', 'toggle_task_status');
add_action('wp_ajax_nopriv_updatemeta', 'toggle_task_status');
function toggle_task_status () {
$post_id = $data['post_id'];
return update_post_meta($post_id , 'task_status', 'open');
}
javascript
jQuery("form").on("submit", function () {
console.log("hello");
var post_id = jQuery("#post_id").val();
console.log(post_id);
var post_data = {
action: "updatemeta",
data: {
post_id: post_id,
}
};
jQuery.ajax({
type: "POST",
url: "http://cloud-accounting.com/wp-admin/admin-ajax.php",
data: post_data,
dataType: "json",
cache: false,
error: function (jqHXR, textStatus, errorThrown) {
console.error("it is not working "+textStatus, errorThrown);
},
success: function () {
console.log("it is working");
}
})
})
and the code gives me success but it doesn't work , I see the same before and after the request