Attachment is just post_parent value of the attachment post object, you can update that via wp_update_post:
foreach( $gallery_array as $value ) {
$the_post = array(
'ID' => $value,
'post_parent' => $target_post_id,
);
wp_update_post( $the_post );
}
Related Posts:
- Upload images and attachments from frontend form
- File upload, uploads only file name
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- How to get the filename from file system and create a download link?
- Front end file upload returning wrong attachment url
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- File path for attachments outside of wp-content/uploads
- Correct Syntax for uploading files to custom directory in WordPress
- Uploading media with the REST API
- Disable Attachment Pages Completely
- How to add a class to the attachment images
- Change the filename format of saved featured images
- How to register images uploaded via FTP in media library?
- Using file_exists to check file in Uploads
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- Rename image uploads with width in filename
- Modify image while uploading
- Adding Featured Image to Post programatically
- Add custom field to attachments in a specific category
- Conditional Statement – check if post has an attachment image
- Specified file failed upload test. wp_upload_handle
- How to upload imagick resource to media in wordpress
- Make WordPress upload directory outside wordpress root with custom url
- Get a Page’s attachments in Gallery order
- Image upload via FTP to wordpress media library
- Adding featured image via PHP
- How to enlarge the media file upload size in wordpress admin
- Use Timber/Twig to pull an image by image ID [closed]
- Adding a querystring to an image URL when clicking ‘insert into post’?
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- wp_handle_upload – The uploaded file could not be moved to wp-content/uploads/2012/09
- Memory errors with media upload, WordPress can’t use more than 96M (while there’s 512 available!)
- Validate Uploaded Image using WordPress’ Built-in Functions?
- Get most recent media upload
- Link to the parent post in attachment page
- Convert all images to PNG on file upload
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- WordPress Search Results for Multiple Post Types
- PDF file randomly breaks upon upload
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- How to upload a file to a folder named after the user_id via plugin
- Need help with Google drive API [closed]
- Can’t upload image using media_sideload_image
- Send multiple attachments with wp_mail in PHP
- Upload multiple images to a Woocomerce product
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Enable custom logo upload if logo is not in header
- NGINX rewrite rules for multisite
- How do I get around “Sorry, this file type is not permitted for security reasons”?
- Change WordPress Upload Folder using wp handle upload
- How do I Import / Upload Files with jQuery AJAX?
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- Returning data instead of echoing/printing
- Blob file download problem
- zip unzip attachments in wordpress
- Upload multiple files in randomly generated folder using wp_upload_bits
- WordPress upload file size error even after raising php limits
- Get uploaded image and attach it to the new post
- Get featured image with custom size outside WordPress
- Why is my max_upload_filesize being limited to 2M? [duplicate]
- Images Uploaded saving onto older/previous year folders
- Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages
- How do I increase the upload size only when editing special pages?
- Convert canvas to image and upload image to server
- how to get attached file url for current post?
- custom plugin with upload files does not work
- How to Make Thumbnail of Post Stay Animated
- Convert all uploaded PNG files to PNG-8 format
- How to decrease the max file upload size without using php.ini or htaccess?
- How to load previous or next attachment with jquery ?
- Some problems in custom widget
- Checking page before applying image restrictions while uploading
- Change image data durgin upload
- Hook on file upload
- Unable to delete related media attachments with deleted post
- Attach and retrive multiple pdf files to post or page
- Sudden Upload HTTP errors, PHP uploads and memory limits are already to high to my taste. Anything else?
- Change upload URL by mime type
- Get list of posts from attachment
- I want url from a file in media using title file
- Crop an image after upload on custom account page
- media_handle_upload fails with gravity form submitted image
- Restrict File Type Uploads by User on Wordress via functions.php
- Get posts associated with media attachment
- Save the outputted image into the Media Library, with a different filename and extension
- Attachments doesn’t update
- WordPress will suddenly stop saving files uploaded by my code (ran in nopriv ajax)
- Name Input from widget displays Sidebar name instead of saved data
- Can’t upload files
- Post Title Not showing up
- Target all images that are not the first attachment
- File Upload with Server in safe_mode
- Edit Image/Image Details – Replace button missing
- Generate and upload screenshot as featured image for user-submitted post
- Pull latest Youtube Video from json url and make new post
- Changing upload directory temporarily
- Can I redirect media urls (not attachment pages) to the post parent?
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?