Gallery
4 min read
A Gallery field holds a list of images from the media library, in the order you picked them. Use it for a photo set on a product, a property or a portfolio item.
Type id |
|
Builder category | Content |
Column |
|
Returns | a list of attachment IDs such as |
Prints |
|
Needs | Pro, Business or Agency plan |
Add the field
- Open WPM Fields › Field Groups and edit a group (see Add and arrange fields).
- Add a field and choose Gallery as its type.
- Set the type settings below and save the group.
A Gallery cannot be put inside a Group or a Repeater, and it is not available in front-end forms (the picker is the WordPress media library).
Type settings
Setting | Default | Effect |
|---|---|---|
Maximum images | 0 |
|
Image size on the site |
| The WordPress image size used when the field prints. The list holds every registered size and |
The settings every field has (label, key, instructions, required, conditional logic, admin column) work as described in Settings every field has.
Edit screen
- Add images opens the media library, limited to images, with several selections allowed. The dialog title is "Add images" and its button reads "Add to gallery".
- Chosen images appear as thumbnails. An image that is already in the field is not added twice.
- Each thumbnail has a × button (screen reader label "Remove image") that removes it from the field. The image stays in the media library.
- Images keep the order in which you added them. There is no drag and drop; to change the order, remove the images and add them again in the order you want.
- Removing every image and saving clears the field.
What is saved
On save the field keeps only what is valid:
- Only attachments that are images. PDFs, other files and IDs that do not exist are dropped first.
- Each image once, in the posted order.
- At most Maximum images entries, counted after the non-images were removed.
- With no valid image the field is cleared.
From code:
wpmcf_update_field( 'property', 'photos', [ 1202, 1203, 1203 ], $post_id );
// stored: [1202, 1203]Writing a value that is not a list (a string, for example) clears the field.
Template usage
$ids = wpmcf_get_field( 'property', 'photos' );
// [1202, 1203] (an empty list when there are none)
foreach ( $ids as $id ) {
echo wp_get_attachment_image( $id, 'large' );
}wpmcf_get_field() returns the stored IDs as they are. If an image was deleted from the media library later, its ID is still in the list; wp_get_attachment_image() then returns an empty string. Use wp_attachment_is_image( $id ) when you need to be sure.
Printed output, with the default image size:
wpmcf_the_field( 'property', 'photos', null, [ 'wrap' => false ] );<div class="wpmcf-gallery"><img width="300" height="200" src="…" class="attachment-medium size-medium" alt="" decoding="async" /> … </div>The shortcode does the same: [wpmcf_field group="property" field="photos" wrap="false"]. Without wrap="false" the <div> is placed inside the <span class="wpmcf-field-value"> wrapper. The printed gallery has no links and no captions; for a lightbox, captions and a grid use the Field gallery widget in Elementor, or loop over the IDs yourself.
Admin list column
With Show in the admin list on, the list shows the images at the field's Image size on the site (set it to thumbnail for compact rows). The column is not sortable and has no filter, and the CSV export leaves the cell empty. See Admin columns.
Page builders
Dynamic image tags in Elementor, Bricks, Divi, Breakdance and Oxygen use the first image of a Gallery. The Elementor Field gallery widget shows all of them. See Page builders overview.
Without a license
Existing values keep printing. On the edit screen the field is shown as locked and its value is kept. See License expiry.
Troubleshooting
- The field shows "Your plan does not include this field type". The license is missing or has expired. The saved images are kept and still print.
- I added more images than the maximum and some are missing. Images beyond the maximum are ignored when you pick them and again when the post is saved.
- An image I picked is missing after saving. Only image attachments are kept. Check the file type in the media library.
- The images are too large in the list. Set Image size on the site to
thumbnailfor the field.
Still stuck? Contact support