WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
[resolved] How to get list of media? (3 posts)

  1. monkeypunch3
    Member
    Posted 5 months ago #

    Is there a controller that allows someone to get a list of media? And if possible also to add media?

    http://wordpress.org/plugins/json-api/

  2. monkeypunch3
    Member
    Posted 4 months ago #

    I found an example of getting media attachments with the controller on this page, http://wordpress.org/support/topic/plugin-json-api-how-can-i-create-post-with-attachments?replies=4.

    I updated it to add the attachments as a property on the response object (IE, $output vs $output['attachments']):

    <?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;    
    
    	    $output = array();
    	    $output['attachments'] = $json_api->introspector->get_attachments($parent);
            return $output;
    
        }
    }
    
    ?>

    Thanks to lego123. I'll post updates to this thread as I make them.

  3. monkeypunch3
    Member
    Posted 4 months ago #

    I was finally able to upload an attachment. Basically, after I was able to successfully update a post I added a new file form field and named it attachment and when I submit the form it uploads and updates the post at the same time. I don't know how to add media without a post yet but this is fine for now.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags