• Resolved Quin

    (@quin452)


    Hello

    I’ve created my own plugin which adds custom meta boxes to my posts.
    In here, I’ve got a custom text field which holds the URL of an image selected in my Media Library.

    <section class="metabox">
            <label for="image-preview"><?php _e('Preview')?></label>
            <input type="text" name="image-preview" id="image-preview" value="<?php if(isset($storedMeta['image-preview'])) echo $storedMeta['image-preview'][0]; ?>" />
            <input type="button" id="image-preview-button" class="button" value="<?php _e('Choose or Upload an Image')?>" />
        </section>

    To display it, I use get_post_meta($_GET['id'], 'image-preview', true);, which does work. However, I would also like to use the metadata for that image, rather than have to add more custom fields to add the functionality I desire.

    Is there a better method to attach an image from the Media Library?

Viewing 1 replies (of 1 total)
  • Thread Starter Quin

    (@quin452)

    Update: I’ve figure it out, or at least I think I have (about to test).
    In the jQuery, I was calling the url for media.attachment. Changing that to ID pulls in the ID for the attachment.
    Now I have a unique identifier to get the meta data ??

    It’s odd how the answer sometimes just pops into your head ??

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Metabox Plugin – Image Upload’ is closed to new replies.