Apologies if this is not a question and belongs more in discussion, but In dealing with image attachments for a portfolio site, what is the benefit to having images be "attached" to a post versus saving the image IDs as an array in a post_meta field?

3 Answers 3


The WordPress "gallery" functionality partly depends on the attachment of the media to the post via the post_parent column.

Specifying IDs in your shortcode allows you to include images in your gallery that aren't necessarily "attached" to your post — that is to say, not uploaded from within your post or page. This flexibility allows you to create and embed any number of galleries containing any number of images!

Note: If you choose to just use the "barebones" version of the [gallery] shortcode in your post or page, only images that are "attached" to that post or page will be displayed.


You can see in the source that shortcode uses get_children, which has quite a comment block in the source, and again you can see that post_parent is a key factor.

There are probably other ways to answer the questions but that is the first that comes to my mind.

  • Appreciate the answer. Just mentioned the same thing to G.M. but (maybe I am being stubborn here) I don't see much difference between attachment/meta if you are passing IDs to the shortcode. Commented Jul 29, 2013 at 19:58

Both the things are same. When an image is attached to a post, an entry is made in the meta table for the attached image's path.

  • 1
    you are referring to an attachment, both the guid and the attachment's meta field point to the image's original URL. when an image is attached, it's post_parent is set as the ID for the post it is attached to. i'm asking if it makes more sense to store the list of attached images as meta for the parent.. or set the attachments as having a post_parent. Commented Sep 5, 2012 at 20:56

As @s_ha_dum says, standard gallery shortcode is one reason.

Another one is that when you open the media uploader from a post there is an option to show only media attached to that post. It's a good helper in site with a lot of images.

Last one comes now to my mind is that you can use WP_Query to retrieve attachments of a particular post without using meta query so having more performant query (it runs only in posts table).

  • Thanks for weighing in on this. I'm confused by the shortcode comments because isn't the shortcode [gallery id="1,2,3"] where all the IDs are listed as a parameter? As far as WP_Query would using the post_parent parameter be any more performant than using the include parameter? The 'attached to' thing is helpful I agree, but I get frustrated with how not-obvious it is to attach/detach and that you can't attach to multiple posts. Commented Jul 29, 2013 at 19:50
  • Regarding gallery shortcode, [gallery] with no param works for children attachments. If you want use ids param, it works, but you have to fill it selecting manually all the images clicking on them one by one. And if you cannot rely on the helper 'uploaded in this post' this can be hard. Regarding using post__in in WP_Query how do you fill it? Most probably setting it to the result of get_post_meta, so you run 2 db queries instead of 1.
    – gmazzap
    Commented Jul 29, 2013 at 20:22
  • I want say that, above all, I understand your frustrations and in my last themes I rely most in attachment taxonomies that in my opinion bring a flexible way to work with attachments.
    – gmazzap
    Commented Jul 29, 2013 at 20:34
  • Good point about [gallery] without parameters. But I think you have to manually type that? When you click to insert a gallery, you then have to check off each image you want to include, which I think is at least somewhat intuitive for WP rookies. Got me a again on needing a get_post_meta to use post__in array. Oh well... my sister is a photographer and she was super frustrated with WP, so I've been thinking about how to make it easier for people like her. Got a link for something I can read on attachment taxonomies? Commented Jul 29, 2013 at 22:25
  • Yes, you have to "check off each image you want to include" but if your sister want a gallery with 50+ images you can spare her 50+ clicks :). For attachment taxonomies, register it as you do for every custom taxonomy just assure show_admin_column and show_ui are true and update_count_callback is setted to _update_generic_term_count. Standard UI to manage media taxonomy is good but not perfect: bulk assigment is not available, but you can implement it...
    – gmazzap
    Commented Jul 29, 2013 at 22:46

Your Answer

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

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