To save the menu order use wp_update_post()
with each attachment ID and its new menu position:
$thisattachment = array();
$thisattachment['ID'] = $thisid;
$thisattachment['menu_order'] = $new_menu_position;
wp_update_post($thisattachment);
EDIT – assuming these are already attachments and you’re updating them? Otherwise you have to insert the attachments first with wp_insert_attachment
Related Posts:
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- How can I bulk delete media and attachments using WP-CLI?
- complex restriction of items in media library
- Edit image / Delete image link
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Unattaching unlinked images
- Show Post ID in “Find Posts or Pages” box in Media Library?
- Gel all image from certain post type
- Can i hide the attachments from media which I uploaded from front end?
- Get the attachment URL on single.php
- Perform a custom (bulk) action in media view
- Show selected images on top in Media Manager
- How to retrieve alt attribute for an attachment (uploaded image)?
- Ordering of gallery images without using shortcode in theme
- Where does the gallery shortcode gets its attachments from?
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- How do you create an attachment ID with Ajax submit? No page refresh
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Get an image from the media library. Struggling with the code?
- Media Library Mess After FTP … /uploads
- Media item permalink goes to source file instead of attachment.php
- wp_get_attachment_image_src calling wrong location
- Removing images deleted from uploads folder, from Media Library
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- Is there a way to add Reattach and Unattach links in image gallery?
- How to retrieve images contained in a post
- How to save media-form on custom tab
- Bulk delete media by year
- Media library upload hook
- How To Retrieve An Image Attachment’s Alt Text?
- How to get attachment file name not attachment URL
- Custom collection in media manager?
- How to cleanly delete attachment but retain original file?
- Trying to hide buttons from Attachment window
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- How can I display custom fields value from attachment media?
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Add_Filter example for wp_get_attachment_link
- attachment url rewrite
- Automatically delete attachments and posts [closed]
- How to delete orphan attachments?
- Adding File Extensions to Attachment Page Permalinks
- Get the title and URL of the attachment parent post
- Confused with attachment mimetype order
- Disable edit media attachments?
- Post Auto Draft Issue
- rename attachments based on parent-post-title on upload
- Rename attachments during upload no matter what filetype
- Link all WordPress images size
- post_author for wp_insert_attachment
- Get the path of the first attached media (single.php)
- Adding width and height to wp_get_attachment_image_src
- Audio file’s length (duration) is missing from Attachment Details in Media Library [closed]
- Insert woocommerce products programmatically with featured image and gallery
- How to delete a custom file from upload directory when deleting its post
- How to filter a post in the Tag Cloud widget, using tags of a media library image attached to the post?
- Attachment page 404
- Query to only return the 2 newest post attachments (images)?
- Clean up images, delete unused image sizes attached to a post type
- What is the best way to store thumbnails for a non-image attachment?
- Change default selection for “Embed or Link”?
- problem in uploading attachment to custom directory
- Add attachment for all images in post
- What will happen if I delete all my attachment type posts from database?
- How can I make an attachment page for pdf uploads?
- filter get_children to return all mime types EXCEPT ‘x’
- Update media library image shown in “attachment details” when using wp_insert_attachment to add item to the media library
- Weird string offset errors when displaying post attachments
- Links to my uploads went crazy
- hide attached images of a post
- How to add a caption to an image attachment in a file list?
- Echo list attachment size in post
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- Can’t sort get_posts by post_mime_type
- All images on one line for each post
- How to list “invisible” Auto Drafts?
- How to add media from front-end to an existing post and edit file title
- Auto delete content in specific folder inside media library
- How is it possible that a gallery doesn’t have attachment ids?
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Unable to delete attached file from folder programmatically
- Attachment file display link text
- Get video attachment ID and display length
- Insert attachments from front end form
- controlling whether upload is attached to post or not
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- Add link to attachment for old posts
- Drupal 6 to WordPress migration – media attachments
- Attachment Metadata not updated while uploading audio files
- Move caption in on attachment page
- delete attachment for one post without deleting actual attachment post
- Count images in post then add class if just one