WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that media are an attachment post type that are children to a post, but how are galleries stored in WordPress?

share|improve this question
You should ask the other way around: "Where does the gallery shortcode gets its attachments from?" ;) – kaiser Oct 4 '12 at 15:15
@kaiser good point. I'm working on a gallery/album plugin and I'm doing research on how WordPress currently handles them. – Manny Fleurmond Oct 4 '12 at 15:17
up vote 1 down vote accepted

This completely depends on how your gallery shortcode looks like.

If you replaced it with something custom, then you'll have to take a look at the plugin (or the theme).

The default gallery shortcode gets it from a query:

$query_args = array(
     'post_status'    => 'inherit'
    ,'post_type'      => 'attachment'
    ,'post_mime_type' => 'image'
    ,'order'          => $order
    ,'orderby'        => $orderby

Then it decides to add additional args for either include or exclude.

Here're the 3 scenarios that add the additional/non-shared arguments.

'include' => preg_replace( '/[^\D,]+/', '', $include )
'exclude' => preg_replace( '/[^\D,]+/', '', $include )
// default
'post_parent' => $id
share|improve this answer
As I thought. Thanks for the clarification. So basically galleries are just images that are attached to a post; 1 gallery per post and since images are children to a post, you can only really attach the images to just one post at a time. – Manny Fleurmond Oct 4 '12 at 15:25
Not really. They're referenced in the post meta table. So every post with an image/a gallery has the attachment IDs in its meta data. – kaiser Oct 4 '12 at 15:44
Oh, they are? Some more research to do. Thank you again, @kaiser – Manny Fleurmond Oct 4 '12 at 15:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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