4

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.

2

4 Answers 4

2
+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

1

By using one of the plugins that already do this:

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

1

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

0
0

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...

2
  • 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.
    – Kevin
    Aug 20, 2010 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, 2010 at 3:06

Your Answer

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

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