WordPress WP-API get images attached to post

so I am trying to use WP-API plugin:

i figured out how to get all posts for custom post type:

Read More
http://domain/wp-json/posts?type[]=customType

and i figured out how to get attachments:

http://domain/wp-json/media/

Now the problem is how to get images attached to single post. if I look at the soruce it seems to suggest a path like:

http://domain/wp-json/media/<postId>/

but I get an error:

[{"code":"json_post_invalid_type","message":"Invalid post type"}]

any Idea how to get this to work?

Related posts

Leave a Reply

3 comments

  1. You can use the “parent” id argument, e.g:

    $ curl http://demo.wp-api.org/wp-json/wp/v2/media?parent=<id>
    

    where is the post’s ID. What we do is ignore all versions of images except the original, which is found by looking for the GUID > rendered value, e.g:

    guid: {
        rendered: "http://demo.wp-api.org/wp-content/uploads/image-belonging-to-this-post.png"
    }
    
  2. As of this moment this functionality does not seem to be supported probably will be when the plugin goes into core but for now it is as is.

    I ended up making my own json API to serve my needs by making the page templates recive emit JSON data.