Support » Plugin: JSON API » [Plugin: JSON API] How can i create post with attachments?

Viewing 3 replies - 1 through 3 (of 3 total)
  • ben.IT


    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.


    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;
                $parent = null;    
            return $json_api->introspector->get_attachments($parent);

    I hope this helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: JSON API] How can i create post with attachments?’ is closed to new replies.