WordPress galleries are not true “objects”, they are just a kind of one time macro. There is no real DB of them, just a shortcode in the content and once you deleted it, there is no gallery any more (except for in the old revisions).
The code you referenced is a relic of the old days in which by default a gallery would have been all the images associated with a post, but those old days are long gone and unless you insert manually, the current way is to add the ids of the images to the shortcode and once the shortcode is deleted…. puff you can’t restore it from any other place except for backup.
Related Posts:
- How do I select an image from Media Library in my plugin?
- Media Library plugins for better file management? [closed]
- How to add subfolders in media library for better organisation?
- How to display .ico files in the media library
- print_media_templates not applied in media manager plugin
- Uploading Images to Media Library via wp_handle_sideload() fails
- image_size_names_choose filter doesn’t show
- Add class=”media_type” when media is inserted into editor
- How to call WP3.5 Media Library manager?
- How do I ‘rebuild’ the WordPress Media library after transfer to new host?
- Proper way to hook wp_get_attachment_url or any other way to change that url in media library
- How can I list URLs of all audio files within my media gallery?
- Migrating to HTTPS only, most media library links need updating?
- Failing to open advanced-cache.php which is breaking Media Library
- Filter pictures in the media library [closed]
- Is there a way to delete images from the Media Library programatically?
- Add file name column to media library
- Is there a way to specify the tab to display when the Media Uploader is displayed?
- How to add ‘Attachment Display Settings’ in custom Media Library?
- Image width tag is less than the image pixel width – why?
- Register an additional image size for only some images in my media library
- WordPress 3.5 Media Manager – Reorder Selectbox items on Media Library Tab [duplicate]
- Gel all image from certain post type
- Inserting a Download Link in the Quick Edit Actions of the Media Library?
- Add size in Gallery Settings in Media Library
- Change default screen option value for media items per page (in media library)
- Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
- Share media among different domains
- Where is the source of the media items filter
- how to download all media files into my computer
- Add image to media library from URL in uploads directory
- Function to get image from media library
- Adding Alt Attributes Automatically when Uploading Images to Media Library
- Media gallery thumbnails 1px
- How to have changes made in media library to be reflected on posts/pages
- Remove the ‘Attachment Details’ section of the wordpress media manager
- Why do I sometimes get an attachment id string instead of a url from an image’s guid field in the post table?
- How to change compression of WordPress uploads including original image
- Featured images get shrunken
- Slow/Not Working Media Library Search
- wordpress not generate thumnails for mp4 videos
- Media Library not showing images properly
- Clean up wp-content/upload/ folder
- The best way to protect uploaded media in WordPress?
- Media Library Grid View Custom Filter
- how to remove thumbnail and LiteSpeed Optimization column in media library list-view?
- Not able to extend wp.media.view.AttachmentsBrowser
- Custom Media Modal and uploading
- Media Library No Longer Displays Images
- Bulk image importing from folders
- Media Library SSL
- Get the largest image based on a thumbnail in a URL
- WordPress does not detect all images in uploads folder?
- Extending Media Gallery – Retrieving values from short code
- How to run custom JavaScript code on gallery attachment image selection
- Media library and posts list problems with WordPress on IIS
- Can I set multiple feature images to multiple posts from the media library?
- “add from media library” tab is super slow [closed]
- Original image not saving?
- Reorder attachements in the media library
- Media library disallows spammy filenames?
- Recalibrate _wp_attachment_metadata Image Dimensions
- Adding Alt Tag Column to Media Library List
- Conditional tag to determine if the user is viewing the Add Media (after clicking Add media button)
- Adding Alt Tag and Dimensions columns to Media Library
- How can I delete duplicate `*-1.jpg` images?
- Extract url of every image in library?
- Thumbnail images missing in WP media library
- Media Library Latency, Lag, CRON?
- Is it possible to share WordPress media files among different domains?
- Is there a way to determine if the media-iframe is visible?
- What would be the URL to display the WordPress image editor with an image from the media library?
- Prevent other editors from viewing images of other editors in Add Media Popup
- Can I remove an image from the Gallery without deleting it from the Media Library?
- Media attachment date and post date
- User media folder for each users on registration
- Larger preview thumbnails in Media Library
- How can I no-index specific PDF files in my Avada WordPress media library so that they don’t appear in search results?
- Media Library http to https
- Filter media library by custom postmeta
- How do you find a file in the media library using the file URL?
- How to limit the amount of images uploaded to the media library within post.php
- Media library corrupted after upgrading to 4.9.6
- query that alternates text posts with images from media gallery
- Can multiple sites under one folder structure share media directories?
- Organising and display thousands of photos in media library
- WordPress Media Delete Logs
- When I’m in post editor and click on ‘Add media’, why won’t it load the media library with this code?
- how to setup user access media library?
- Get filenames of available image sizes
- Use the “Media Library” in Frontend
- Why is my upload / Select media library button empty?
- All the Images in Media Library is showing broken links
- Broken image links in media library after restore
- Add Filename Colum to Media Library
- create a user’s owned folder on user registration
- How to bulk edit taxonomies for attachments
- Block non logged in users from accessing the media library
- Remove Edit Attachment Button in WordPress Mediathek -> see Screenshot
- Editing alt text in media library