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

  • 1
    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

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
|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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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