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
- How to change upload directory in wp_handle_upload
- Decrease file size upload in Media
- How to add a class to the attachment images
- Adding a custom image upload size and making it selected by default?
- Change the filename format of saved featured images
- Image Upload “exceeds the maximum upload size for this site”, but php.ini is correct
- How to register images uploaded via FTP in media library?
- Failed media upload: “The uploaded file was only partially uploaded.”
- Create Image Uploader for Widget
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- Modify image while uploading
- Debugging upload problem: What part of WP does actual image-resizing?
- How to resize image on client-side before upload?
- Add custom field to attachments in a specific category
- Conditional Statement – check if post has an attachment image
- How to upload imagick resource to media in wordpress
- Accessing a random image via ajax
- Make WordPress upload directory outside wordpress root with custom url
- Is it unsafe to put php in the /wp-content/uploads directory?
- WordPress media upload “HTTP error”
- Adding featured image via PHP
- How to enlarge the media file upload size in wordpress admin
- Restrict WordPress File Type Uploads by User Type
- Modify Maximum upload file size text
- Upload a json file in php [closed]
- page template for attachement page?
- Custom image upload
- 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
- Upload Image in a WordPress page using PHP
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- how to retrieve uploaded url of zip files
- Why is $_REQUEST an empty array in admin-ajax.php?
- WordPress Search Results for Multiple Post Types
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- Need help with Google drive API [closed]
- Send multiple attachments with wp_mail in PHP
- Upload file could not be moved to wp-content/uploads
- wp_mail file attachment not being placed in upload folder?
- How do I Import / Upload Files with jQuery AJAX?
- WordPress function when file is uploaded, deleted or edited
- Can I get an email notification when media is uploaded to the media library?
- Returning data instead of echoing/printing
- Upload multiple files in randomly generated folder using wp_upload_bits
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- How do I increase the upload size only when editing special pages?
- Get URL of Featured Image After wp_insert_post()
- Custom upload folder
- WordPress İmages Upload & Delete Error
- how to get attached file url for current post?
- Allow user to Upload image and manipulate it on the frontend
- Attaching images to posts manually (i.e. with custom code, without the use of an API)
- How to load previous or next attachment with jquery ?
- Some problems in custom widget
- Checking page before applying image restrictions while uploading
- Add class to all img if they have a certain ACF field
- Hook on file upload
- I can’t set image ad fatured programatically
- How can I update WordPress plugins or WordPress itself in all server?
- async upload not working when not logged
- Unable to delete related media attachments with deleted post
- WordPress loading all local images from specific directory?
- Trying to generate a CSS file in wordpress uploads folder
- Maximum file Upload
- Change upload URL by mime type
- Right path for renaming a file in uploads folder
- WordPress file upload
- Upload images from one server to an other in wordpress
- Crop an image after upload on custom account page
- Restrict File Type Uploads by User on Wordress via functions.php
- wp_delete_attachment not working with multiple values
- Renaming “Expand Details” within “Add Media”
- Save the outputted image into the Media Library, with a different filename and extension
- 403 (Forbidden) delete file image in themer folder
- Is custom behaviour possible when asynchronously uploading?
- How to resize an image server-side before upload?
- Name Input from widget displays Sidebar name instead of saved data
- Can’t upload files
- Post Title Not showing up
- Edit Image/Image Details – Replace button missing
- How to automatically convert images to WebP on WordPress?
- Generate and upload screenshot as featured image for user-submitted post
- Pull latest Youtube Video from json url and make new post
- WordPress directories not writable after PHP version upgrade
- Upload multiple files via ajax from an HTML file input
- get_post_meta returns on side but it doesn’t return on bottom of admin page