Hi,
I am also concerned by his issue.
Does anybody get an idea/snippet ?
Same here… I’v tried passing the attachment id, attachment object, then the attachment object as an array for the &attachment variable unfortunately nothing seems to stick. What gives?
Hi guys, just wanted to contribute a quick fix solution for what I was trying to achieve.
I added the following code on line 121 of json-api/models/post.php
if (isset($values['media'])) {
foreach($values['media'] as $att){
$attachment_id = wp_insert_attachment(get_post($att), false, $this->id);
$this->attachments[] = new JSON_API_Attachment($attachment_id);
}
}
This will allow you to pass an array of attachment id’s to the &media variable and it will link them to the new post.
I also wrote a simple custom controller called attachments/get_attachments to get unattached files as well. If you need to view unattached files just feed it a &parent=0, to see all files use &parent=null.
json-api/controllers/attachments.php
<?php
/*
Controller name: Attachments
Controller description: Basic introspection methods for fetching attachments
*/
class JSON_API_Attachments_Controller{
public function get_attachments(){
global $json_api;
if($json_api->query->parent !== "null")
$parent = (integer) $json_api->query->parent;
else
$parent = null;
return $json_api->introspector->get_attachments($parent);
}
}
?>
I hope this helps.