Gallery field
Purpose
An ordered list of images from the media library.
Field type name
gallery
Settings
| Setting | Description |
|---|---|
| Instructions | Shown to editors below the field label. (max 2000 characters) |
| Return Format | What cafe_get_field() returns. |
| Image Size | Size of the image URL that cafe_get_field() returns. Choices: every registered image size (e.g. Thumbnail 150 × 150, Medium 300 × 300, Large 1024 × 1024) and Full size. |
| Allowed File Types | Image formats editors may use, picked from a grouped dropdown (JPG, PNG, WebP, …) or typed as MIME types. Empty = every image format. |
| Minimum Images | Fewest images a non-empty gallery may have. (min 0, whole number) |
| Maximum Images | Most images the gallery may have. Leave empty for no limit. (min 1, whole number) |
| Allow Duplicates | Allow the same image more than once. |
| Translation | How the field behaves in other languages: translate, copy, copy_once or do_not_translate. Used on top-level fields when WPML is active. See WPML. |
| Width | Width on edit screens, to place fields side by side: 100 (full), 75, 66, 50, 33 or 25 (%). Phones always show full width. |
| Label per language | The label and instructions per language code while editing in that language, e.g. {"nl": {"label": "Prijs"}}. Set on the Translation tab when WPML is active. See WPML. |
PHP return value
A list in gallery order. Each item follows Return Format: the image array (same shape as Image), the ID, or the URL. Deleted attachments are skipped. Nothing saved → null.
Example
// Add, remove and reorder by saving the new list:
$ids = cafe_get_field( 'photos', $post_id, null, [] ); // return_format "id"
$ids[] = $new_image_id; // add
cafe_update_field( 'photos', $ids, $post_id );
foreach ( cafe_get_field( 'photos' ) ?? [] as $image ) { // return_format "array"
echo wp_get_attachment_image( $image['id'], 'medium' );
}