[wp-hackers] Attaching photos to multiple posts

Andrew Nacin wp at andrewnacin.com
Thu Feb 3 23:56:57 UTC 2011

On Wed, Feb 2, 2011 at 6:40 PM, William Davis <will.davis at gmail.com> wrote:

> On uploading it again: That's a lot of extra work (finding the image,
> uploading it, editing the cutline and crop, etc.) that a lot of newsrooms
> don't have.
> Jane: On choosing it from the media library: You can't select a photo from
> the media library that's attached to another post except to embed it. As
> mentioned below, we don't embed images.
> Otto: I mentioned postmeta and taxonomies earlier. Two reasons I rejected
> these were that oftentimes we want to edit the caption between two different
> use cases (for example, a photo of our governor on one story might have a
> full description of what he's doing, while the other might just simply state
> his name and use the photo for illustrative purposes; and that we would want
> to order the photos as well, which can certainly be done with postmeta and
> taxonomies but not as easily as, for example, defining menu_order.
> The problem is as follows: For our purposes (and I understand this probably
> isn't a core feature) we need an easy way to attach file photos to posts
> (for example, on many continuing stories we'll use the same photo three,
> four, five times). As I mentioned already, uploading it multiple times is
> rather cumbersome.
> Thanks for your thoughts thus far already.
> Will

One problem is that you can't have your cake and eat it too.

Allowing a photo to be associated with more than one post at a time means
that you can't edit the caption. And yes, coming from journalism, I
absolutely see the use case in associating the caption with the distinct
point of attachment of the photo, rather than the photo itself.

That leads me to the next point, which could be that uploading it again
might actually be the most painless way to do it. That allows you to crop or
scale things as well as customize captions and metadata. (Even media credit
could be customized at the point of attachment, rather than the photo; for
example, over time a photo might become a 'file photo' rather than the
original photographer, which sometimes the policy in media organizations.)

The solution? I'm not sure, but I see it less as a technical one and more as
one that is custom to your particular implementation.

Perhaps a method that allows copying of attachments -- the record is
inserted as a new attachment and new files are generated. But you can still
keep them linked via postmeta fields and synchronize the data you
specifically want, whenever you wish to modify one or the other. That keeps
the burden down of downloading then uploading a file whenever you want to
reuse it.

I also like the simple approach of tying attachments to posts not only via
post_parent but also with postmeta on the parent post. (Taxonomy works too.)
Then to get attachments tied to a post, you'd query by postmeta value
instead. This doesn't break the conventions of how WordPress stores
attachments, but still provides the ability of not needing to embed images
in post content. You still have issues with attachments but perhaps that's
another thing that can go into postmeta.

I agree strongly with Otto that it isn't about the solution, it's about the
problem. Identify exactly what you want to achieve, and then find a solution
that fits your needs. If our use cases are close, I'd be willing to work on
this as well, as I'd like to leverage it myself somewhere, so let me know

Hope that helps,

More information about the wp-hackers mailing list