Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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>
        <?php
        $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;
        }
        ?>
      </select>
share|improve this answer
    
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. –  Jens Törnell Aug 10 '11 at 18:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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