How can I attach a file using Wordpress custom fields / meta boxes?

Posted by shipshape on Stack Overflow See other posts from Stack Overflow or by shipshape
Published on 2010-04-01T20:54:36Z Indexed on 2010/04/02 10:43 UTC
Read the original article Hit count: 428

Filed under:
|
|

I am using Wordpress's add_meta_box() function to add customized meta fields to the Add New Post page, like this. I want one of these fields to allow the user to upload a file, so that a single image, pdf, audio file, or video can be associated with the post.

The closest example I've seen is this one. Unfortunately it does not suit my needs, as I want my file to be processed by Wordpress's Media Uploader - so it should appear in the Media Library afterwards, and thumbnails should be generated according to the Media settings.

I think ideally there would be a way to tap into Wordpress's existing Add Media dialog, and simply output the URL of the uploaded file into a text box, but I don't see how to do that. This question is similar, but the answers are a little clunky - I would like to keep this super simple for my end users.

How can I accomplish this? Please do not recommend plugins such as Flutter or Magic Fields - I have tried these and they do not suit my purposes (I want the images to be processed by Wordpress's Media Uploader). I am using Wordpress 3.0-alpha.

Thanks!

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about custom-fields