Getting ID from ajax response of async-upload.php

Its a wordpress+jQuery question. Can’t post it on stackoverflow because i believe it involves wordpress knowledge too.

What I am trying to achieve:
I am attaching the wordpress async media uploader on “add post” page metabox so user can upload lots of images simply drag and drop them into the uploader and don’t have to insert them once at a time (see the image).

image uploader

I am saving the attachment ids on a post meta so user can attach one image to more then one post.

Question: When the uploader send the upload request to the async-upload.php it sends back an html response which contains the whole form for adding title, caption, description for the attachment. Very first of the response comes with this:

<input type="hidden" id='type-of-106' value="image" />

You can see a full response here.

My question is how to I get the attachment id from that html response? I am guessing I have to listen for any ajax response that comes from the async-upload.php then look through the response.

2 Answers
2

I could but i really don’t want to post the work of others here, even if it’s open source code.

Rilwis Meta Box Class has a plupload field, which has a custom upload handler.
If you mind to take a look: https://github.com/rilwis/meta-box

resp: https://github.com/rilwis/meta-box/blob/master/inc/fields/plupload-image.php#L31

The answer is there. This code,or at least the idea, gives you much more control over the response.

Leave a Comment