XML-RPC API, , , curl, , wp.newPost:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/xmlrpc.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = array(
'post_type' => 'post',
'post_content' => 'This is the post content',
'post_title' => 'This is the post title',
'post_status' => 'publish',
);
$params = array(1, '<user>', '<password>', $content);
$params = xmlrpc_encode_request('wp.newPost', $params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_exec($ch);
curl_close($ch);
, wp.getPosts, , , :
$filter = array(
'post_type' => 'post',
'post_status' => 'publish',
'number' => 50,
'offset' => 0,
'orderby' => 'post_title',
);
$fields = array(
'post_title',
'post_author',
'post_id',
'post_content',
);
$params = array(1, '<username>', '<password>', $filter, $fields);
$params = xmlrpc_encode_request('wp.getPosts', $params);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
$response = simplexml_load_string($response);