[wp-hackers] Custom Post Types and Media Attachments

Becky Resler becky.absolute at gmail.com
Fri Dec 10 15:31:35 UTC 2010


I am currently working on a project that utilizes a custom post type
with custom meta boxes. I have removed the default content editor for
this custom post type ['supports' => array('title', 'thumbnail')]. In
one of the custom meta boxes, I have a textarea with a WYSIWYG editor.
I would like to be able to embed images into the content of this
textarea using the WordPress Media Library. I was able to add the
*Upload/Insert* icons above the editor by using some code I found in a
tutorial online.

The interface for adding/editing a post for my custom post type can be
seen here:
http://dl.dropbox.com/u/10219458/Screenshots/WordPress/custom-post-type.gif

Clicking on the *Add an Image* icon in the *Products* meta box does
open the media library/upload interface in a lightbox. I am able to
upload an image, and it is attached to the post (of the custom post
type). However, the *Insert into Post* button is not there for the
image so that I can insert the newly uploaded image into my custom
textarea editor. The *Insert into Post* button is also missing when I
try to add the same image to a regular Post or Page. I *am* able to
set this image as the featured image for my custom post type.

This screenshot shows what I get when I upload an image from the
*Products* meta box. As you can see, the *Insert into Post* button is
missing.
http://dl.dropbox.com/u/10219458/Screenshots/WordPress/uploaded-image.gif

If I try to insert an image (into my custom textarea editor) that has
been attached to either a Post or a Page or one that has been uploaded
via the Media Library interface (and is attached to nothing), the
*Insert into Post* button *is* available, and I can successfully
insert it into the textarea in the *Products* meta box.

I did a test for another custom post type (on a different project)
where I do have the default content editor ['supports' =>
array('title','editor')] and no custom meta boxes. When I uploaded an
image, it was attached to the post (of that custom post type) and the
*Insert into Post* button *was* available.

So ... it appears that as long as I upload an image to the main
content editor, the *Insert into Post* button is available wherever I
need to insert the image, even into a custom meta box field. But if I
upload an image from a custom meta box field, the *Insert into Post*
button goes MIA.

That long winded explanation leads me to my question ... is the
WordPress Media Library only really supported by the main content
editor and featured image? Is it not meant to be used to add images to
custom meta box fields?

Or is this a bug?

Or have I screwed up my code somewhere along the line? (BTW ... I'm
running WP 3.0.3)

Thanks in advance for any help.

--
Becky Resler
Web Programmer | Absolute Marketing Group


More information about the wp-hackers mailing list