I have done all pages listed in core PHP application using wordpress REST API with CURL but I can’t delete that pages with CURL.I got message “{code: “rest_cannot_delete”, message: “Sorry, you are not allowed to delete this post.}” every time.

Here is my code.

$url = 'http://localhost/wordpress/wp-json/wp/v2/pages/37';
$postdata = 37; //pageID

function callrestapi_curlDelete($url, $postdata) {

    $postdata_json = json_encode($postdata);
    // Get cURL resource
    $curl = curl_init();

    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
    ));
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata_json);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    // Close request to clear up some resources
    curl_close($curl);

    echo json_decode($resp, TRUE);

}

Read more here: How to delete a page using wordpress rest api through curl


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: