i build a system that allow the user to delete post by ID with wordpress API. this system works fine on localhost, but after i uploaded the site to production i can't delete the post all i get is an error message

DELETE https://mysite/wp-json/wp/v2/student_list/6954 403 (Forbidden)

i don't understand what is the difference between production and localhost environment. the code is the same and the nonce works as far i can see the js file:

function deleteStudent(e) {
  let thisStudent = jQuery(e.target).parents("tr");
    beforeSend: xhr => {
      xhr.setRequestHeader("X-WP-Nonce", programsData.nonce);
      `${programsData.root_url}/wp-json/wp/v2/student_list/` +
    type: "DELETE",
    success: response => {
      // thisStudent.slideUp();

      console.log("student deleted");
    error: response => {
      console.error("student was not deleted");

ths function.php

 wp_localize_script('student_management', 'programsData', [
        'root_url' => get_site_url(),
        'nonce' => wp_create_nonce('wp_rest'),

the only thing i know is different is that the live version was upgraded to wordpress 5.3 and the localhost is on 5.2 - i don't think it's relevant

  • Are the server environments identical? Could it be that your prod environment simply denies any DELETE request? – kero Nov 13 '19 at 10:59
  • Are you logged in to both? – Jacob Peattie Nov 13 '19 at 11:00
  • no . i can delete posts. and yes i'm logged in as the same user – Doron Davidowitz Nov 13 '19 at 11:02
  • "i can delete posts" - doing this via /wp-admin is not the same as sending an http request of type DELETE. Can't check right now but I'm pretty sure, WP internally does not use this http type – kero Nov 13 '19 at 11:04
  • 1
    No. It could be that your production host does not admit requests with Delete method. Azure webapps for example, only allows Post and Get. – Jesús Franco Nov 14 '19 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.