wp_insert_post() return the ID of the post if the post is successfully added to the database. Save this ID in variable, and than create foreach images if you want to attach the same images for each post.
Try something like this:
Related Posts:
- How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
- How to get image title/alt attribute?
- How to Fix HTTP Error When Uploading Images?
- How to set featured image to custom post from outside programmatically
- Delete original image – keep thumbnail?
- Set Featured Image Front Frontend Form
- media_sideload_image generates blank?
- How to change _wp_attachment_metadata specific value in SQL?
- Set (featured) thumbnail for post?
- How can I get a different image size, if all I have is the link?
- Delete all thumbnails for a post
- How to set an attachments parent post id in code?
- How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
- How do i show wordpress attachments from current post?
- Need clear explanation about medias/files/attchments
- Image still attached to post even after removing it as featured image
- Exclude featured image from attachment loop
- How to create resized versions of images added with wp_insert_attachment
- Show Multiple Size URL of one Featured Image/Thumbnail?
- Check if parent post is sticky on attachment page?
- How to attach images that I “insert from url” into the post?
- Moved server, and WP now uses original images for all thumb sizes?
- replace featured image from frontend
- Featured Image URL is Showing but not thumbnail
- Get all images from posts with maximum number and without featured image
- Why not attaching images after impoting using wp cli
- Close featured image modal windows with JS
- How do I get image url only on the_post_thumbnail
- Add class name to post thumbnail
- How to disable WordPress from creating thumbnails?
- How to retrieve image from URL and set as featured image/post thumbnail
- Programmatically get images by URL and save in uploads folder
- How do you remove hard coded thumbnail image dimensions?
- How do you get the post thumbnail size?
- Setting a post’s featured image from an embedded YouTube video
- How to get featured image’s width and use elsewhere in template?
- set_post_thumbnail_size vs add_image_size
- Minimum Dimensions Requirement for Featured Image?
- Generate Thumbnails only for Featured Images
- Get the first image from post content (eg.: hotlinked images)
- How to get all featured image sizes and their URLs?
- How to Dynamically Resize WordPress Image On-The-Fly (custom field/theme option)
- How to add post featured image to RSS item tag?
- How do I regenerate thumbnails?
- Display thumbnail only if requested size exists
- the_post_thumbnail responsive srcset not populating with custom image size
- Set custom name for generated thumbnails
- Post thumbnail alt title
- Get Featured Image via direct sql query
- Get featured image on Blog Index
- the_post_thumbnail hard cropping not working no matter what
- Can I refresh the thumbnails programmatically?
- How to add multiple image sizes of the same size with add_image_size
- New image size version only for the Featured Image file
- wp_get_attachment_image_src always returns full-sized image
- Get featured image URL by page id
- change set_post_thumbnail_size according to post type admin page
- Add Title Attribute to WordPress Image the_post_thumbnail
- Can’t extract and set SVG dimensions
- Getting Thumbnail Path rather than Image Tag
- Display Category Thumbnail and links in Woo commerce
- the_post_thumbnail with lazyload JQ plugin
- Replacing Gutenberg Featured Image control?
- How to find attachment by it’s name?
- Display Post Thumbnail Without Being Featured Image
- Featured Image of Video from oembed
- oEmbed, thumbnails and wordpress
- wp_get_attachment_image_src() and custom sizes
- get_the_post_thumbnail() doesn’t taking style attribute
- Prevent WordPress from cropping GIF files
- Post thumbnail outside the loop
- media_handle_upload for local files?
- What’s the difference between post thumbnails and featured images (if any)?
- Getting custom-sized featured image’s URL?
- What is your take: TimThumb vs. WordPress Thumbnails? The great debate [closed]
- How to crop thumbnail height to auto with set width
- Retrieve 1st image in post and set it as featured image, when post is saved/updated
- Use thumbnail image using url of that image
- Retrieve featured image as object
- How do I add the featured image to the_content after the first paragraph?
- Showing a placeholder/default img, if no featured image is set
- Re-order media links?
- Multiple featured image thumbnails for post types (Multiple Post Thumbnails plugin)
- the_post_thumbnail scaling not hard cropping
- Skip posts without a thumbnail in loop
- Insert an image into a post by API
- wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Getting thumb from wrong loop
- Set featured image for multiple posts
- Image uploader with “Set Featured Image” link on front end
- adding an id to the_post_thumbnail
- Featured image size in ADMIN panel?
- Featured image with the same height thumbs returns wrong thumb
- How can I display my featured image correctly inside my single posts?
- How to change the naming of the resized image files
- Featured image upload finished hook
- How to get featured post title & image using JSON API?
- Generate thumbnail for images with the same size as thumbnails
- Set post thumbnail as background
- Display thumbnail only on the very first post in the loop?
- How to show featured image CAPTION only if it exist