This is what I want to do:

  1. In the media uploader, add a link "Use this attachment ID as custom field".
  2. Add the attachment ID in a custom fields meta box.

I've searched for hours for a plugin that does this but found nothing. Code examples, plugins, hints. Anything might be helpful.

2 Answers 2


I found it:



When you upload attachments to a post/page they become child elements of that post/page.

What you can do is provide a drop down in your custom field to list all uploaded files to the uploader for the current post/page. This is the code I used to show a list of files so the user could select which one was a floor plan image:

      <select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;">
        <option value="" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], ""); ?>>No Floor Plan</option>
        $args = array(
            'numberposts'     => -1,
            'orderby'         => 'menu_order',
            'order'           => 'ASC',
            'post_type'       => 'attachment',
            'post_parent'     => $post->ID,
            'post_mime_type' => 'image'
        $image = get_posts($args);
        if($image) {
            foreach($image as $key => $data) : ?>

                <option value="<?php echo $data->ID; ?>" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], $data->ID); ?>><?php echo basename ( get_attached_file( $data->ID ) ); ?></option>

            <?php endforeach;
  • I guess that could be useful. However let's say you uploaded the image directly in the media library or in another post, then this code is not that helpful. Vote up anyway. Aug 10, 2011 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.