XMLRPC Delete WordPress Post with wp.deletePost

I am trying to delete a wordpress post with XMLRPC, I created a function but it returns a strange thing:

function deletePost($rpcurl,$username,$password,$post_id) 
{
// xmlrpc settings
$params = array(0,$username,$password,$post_id);

// run xmlrpc
$request = xmlrpc_encode_request('wp.deletePost', $params);
$ch = curl_init();  
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);  
curl_setopt($ch, CURLOPT_URL, $rpcurl);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_TIMEOUT, 1);  
$results = curl_exec($ch);  
curl_close($ch);

// testing
var_dump( $results);
return $results;  
}

Here’s what is being returned (once stripped some of the xml tags down):

<name>faultCode</name>
<value><int>-32601</int></value>
<name>faultString</name>
<value><string>server error. requested method wp.deletePost does not exist.</string>

Related posts

Leave a Reply

1 comment

  1. It actually is what it says it is…there is no such method on xmlrpc server, because wp doesn’t allow to delete posts by itself… But in the xmlrpc there is a method for blogger api called blogger.deletePost. It should do what you want. As I look at your code, I think you only need to fix two things, change your third line of code into

    $request = xmlrpc_encode_request('blogger.deletePost', $params);
    

    and also, your $params should be an array, with values on [1] being post_id, [2] username a [3] password.

    EDIT: It obviously exists from version 3.4., so you could either use the solution above, or use the wp.deletePost with $params with values on [1] username a [2] password and [3] post_id.