How can you determine whether an image is merely attached or has actually been inserted into a post?

Bear with me. I promise there’s a question when I’m done 🙂

In WordPress, you can upload images while editing a post and have the option to insert them into the content (or not).

Regardless, the image appears to be “attached” to the post when viewing the Media manager.

Does WordPress place any references into the database to differentiate an image that’s been attached and also inserted into the post content? Or conversely, an image that’s been attached to a post but has NOT been inserted into the post content?

Why do I want to know this?

I would like to allow the user to upload images that will be written above the post content (a row of images) by simply uploading them via the post attachment wizard.

But they may also upload some images that they only want to appear in the content, so they will click “insert into post” in that case. Unless I have some way of differentiating images that have actually been inserted vs images that have merely been attached, they will get duplicate images, one in the post and one at the top of the post.

Any thoughts on how to do this?

I suppose an alternate approach would be to add a checkbox to the attachments editor to flag an image for display as a post header attachment, then do a lookup for images attached to the post with the special flag.

3 Answers
3

I used nextgen gallery plugin to do something like this. Actually I’ve used only half of that: the end user uploads images through the plugin’s interface but the actual display inside the post is done with a custom shortcode.

I don’t think there is a way to tell if an attachment has been inserted in the post, short of examining the post content source.

Leave a Comment