add below code after echo $attach_id....
set_post_thumbnail( $post_id , $attach_id);
Related Posts:
- unable to write to the database while uploading images
- WordPress Media URLs?
- How to upload post thumbnail while wp_insert_post?
- How do I detach images from posts?
- Too many connections to server
- creating front end image uploader that uploads images as posts
- Errors when uploading images in WP 3.5
- wp-cli post create & media import issues
- WordPress Media Uploader in page template (On Front-end)
- Removal of Media Gallery pictures
- How to get the last selected media alignment setting?
- WordPress Automatic Filename Changer
- Remove Featured Image & All Media Uploaded to the Post
- Uploading images in custom post form
- Upload attachment from external site
- How to get all inline images in post content? [duplicate]
- Inserting Media to WordPress Posts
- How to call WordPress First Image Post or else Attached Image or Default
- Site/Post preview is not working on all social media
- Post images are not displayed in media library
- how to create other sizes of original image in one go wordpress uploads
- Customizing individual images on posts
- Update all images url imported from HTML pages
- Disable Media uploader to users
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- Broken images after importing posts and opening in Gutenberg
- Inserting Media on New Post But Hides Previous Uploads for Editor/Contributor
- What is the proper use of guid for images in wp_posts?
- Optimize blog that serves hundred of images and videos
- Images being uploaded via WP Media are not attached even they are used by some CPT posts
- WordPress portfolio posts: media not displaying if several images
- How to delete Full Size options from post Add Media?
- What are the benefits of setting a “featured image” for a WP blog post?
- preg_replace not removed “class”
- update image path with words starting uppercase to lowercase chars
- Get images attached to a specific page
- How to only publish posts with image in it
- Lock post editing to one user at a time – wp_check_post_lock
- Front end post submission form with duplicate type fields
- Make insterted image point to post url instead of attachment page
- Get URL from all images in a post
- Is there a way in WordPress to convert images to WebP without a plugin?
- Disable posts generated from image uploads
- Replace image name on upload to the new post name on front-end form
- Edit the post title from the frontend
- how to give multiple post thumbnails to a post
- Display a mixed list of posts and media
- Posts page not showing correct image
- Images showing up in Post Editor, but not in Published Post
- How to allow multiple thumbnail upload for Posts?
- Image behind the post’s title
- get_children returns older images
- How to display post title inside thumbnail?
- Get featured image with custom size outside WordPress
- How to remove text and retain in caption image using the_content function
- How to retrieve certain number of images from a wordpress post?
- WordPress creating images if uploaded image is greater than 960px on one side?
- Show more than 200 images in one post
- Disable image rename on upload
- Hide thumbnail if there is a gallery on the post
- Image on rss feed on post
- Change the background of each post according to the category
- Create post from form with image
- Stop Authors from submitting spam post
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Assign custom class to post content images
- How can to use the players from the Media Widgets in the body of a post to play audio and video files
- Extra Theme – Fit image inside of Featured Post Slider
- Post thumbnail height problem
- Get attachment if matches a variable
- Media Library is not loading on grid view in admin panel
- Bug with post titles [closed]
- Is there any SEO impacts on unattached vs attached images for a post in WordPress?
- Blurry Images WordPress 5.8.1
- Full width images within post content
- Front end post or photo or both
- How to automatically convert images to WebP on WordPress?
- Import alt text in set_post_thumbnail
- Search doesn’t display posts with images
- Displaying all images from a WordPress post (including media library)
- How to move all images in a post to a single gallery for a bunch of posts?
- Uploading media to wordpress API with C# HttpClient
- Inside post image title has been posting as a post title on my main post page
- Download button under all images WordPress
- How To Convert External Image URLs To Own Website’s Uploaded Images Automatically?
- website images getting corrupt automatically
- Images and menu links disapearing after saving
- When inserting media file in a post or page, show file name under the thumbnail
- Redirection – bulk edit 404s to new tomain
- how to display the actual size of the picture in post
- Does WordPress Super User or Administrators can create and edit post and media on behalf of a user
- Xhr.send : PDF upload failed with status 400 and response 0
- How to upload multiple images to use as gallery in Kirki Framework
- How do I display a PDF thumbnail as a link to the PDF without uploading the image
- Modify upload directory to use post category slug in file path on multisite installation
- Set Featured Image of a post
- Is there a way to eliminate flyout menus when adding a post?
- Convert base64 string to WordPress attachment uploads multiple images instead of a single one
- Undefined array key “width” in wp-admin/includes/image.php error when publishing post or page
- Featured Image add tab