I am using wp.uploadFile to upload an image, once climb need to assign a post_parent, DO NOT seek to be added as a featured picture, but it is assigned the ID of the post where he was raised.
If I add as outstanding image then edited the post at the wp_posts table and post_parent field is 0.
I tried this:
include_once('IXR_Library.php');
$client = new IXR_Client('http://ift.tt/1Bn1FDQ');
$username='demo'; $password='demo';
$content = array(
'post_status' => 'draft',
'post_type' => 'post',
'post_title' => 'Title',
'post_content' => 'Message',
// categories ids
'terms' => array('category' => array(6))
);
$params = array(0, $username, $password, $content);
$client->query('wp.newPost', $params);
$post_id = $client->getResponse();
$content = array(
'name' => basename('http://ift.tt/1FFwe6H'),
'type' => 'image/jpeg',
'bits' => new IXR_Base64(file_get_contents('http://ift.tt/1FFwe6H')),
true,
);
$client->query('metaWeblog.newMediaObject', 1, $username, $password, $content);
$media = $client->getResponse();
And so
$content = array(
array(
'name' => basename('http://ift.tt/1Bn1Leq'),
'type' => 'image/jpeg',
'bits' => new IXR_Base64(file_get_contents('http://ift.tt/1Bn1Leq')),
'overwrite' => true,
'post_id' => $post_id
)
);
$client->query('wp.uploadFile', 1, $username, $password, $content);
$clientResponse = $client->getResponse();
print_r($clientResponse);
The first code uploads the image but not assigned to the post and the second gives error "Array ([faultCode] => 500 [faultString] => Could not write file (Empty filename))"
Any idea? Thanks.
Aucun commentaire:
Enregistrer un commentaire