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.

I need a way to create a custom field that will let me pick an image from the media gallery. How do I do that?

The custom field should have a button that when clicked will take me to the media gallery and place the src destination url within a input text box.

looking for a plugin or online tutorial and I'm having little luck.

share|improve this question
    
Could you be a little bit more descriptive? Where is this field? What do you mean by 'pick'? What are you trying to accomplish? –  John P Bloch Aug 19 '10 at 19:24
    
have you seen wordpress.stackexchange.com/questions/639/… ? –  hakre Aug 25 '10 at 21:08
    
no I have not, thanks –  Thorn007 Aug 25 '10 at 22:55

4 Answers 4

up vote 2 down vote accepted
+50

A few weeks ago I added a feature similar to Magic Fields.

Here's the github project. The most important thing is in this file: js/custom_fields/media_image.js

share|improve this answer

By using one of the plugins that already do this:

http://wordpress.org/extend/plugins/custom-field-template/

share|improve this answer

This to me sounds like the post_thumbnail feature in WordPress. It will add a box on the right hand side, below the tag box. By default the box displays a link "Set featured image".

When you click on it the media gallery popup opens and you can pick a picture you have previously uploaded to the post as the featured picture.

You can then use:

if (has_post_thumbnail()) {
  the_post_thumbnail();
}

in you theme to display the featured picture.

To enable post_thumbnail you just need to add:

add_theme_support( 'post-thumbnails' );

to your theme's function.php

share|improve this answer

To answer your question a bit sideways, are you open to an alternative? I suggest adding a photo to a post, filing the post under a specific category for your images, and maybe, depending on your needs, adding a text-only custom field to retrieve that specific image.

$image = get_posts('cat=the_category&meta_key=the_key&meta_value=the_value');
foreach($image as $img){
    setup_postdata($img);
    //whatever your markup is...
    echo '<p>'.the_content().'</p>';
    //or
   echo '<p>'.$img->post_content.'</p>';
}

Just a thought...

share|improve this answer
    
interesting, might take a look at that idea. However, I have seen the concept I'm talking about used with audio for a podcast I run. It may be that I need to look at their code and see how they approached the issue. –  Thorn007 Aug 20 '10 at 2:38
    
I'm in the process of re-developing my business website in WordPress, and I currently have a few images being rendered to the page this way. Unfortunately, I load about 10 images into a slideshow. Just today I had the idea to load all ten images into the same post and only have to call one post instead of ten. Now to go back and clean up the code! –  kevtrout Aug 20 '10 at 3:06

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.