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?
- Add custom Attachment Display Setting for images
- There’s a way to scale media (images) at 50%?
- Publish pending article from front end with a button?
- Replacing all attachment links in post with media file link
- Alter media caption/description conflict in WordPress?
- Restrict the number of images to upload per post
- Developing a secure front end posting form
- How to remove images from showing in a post with the_content()?
- Image size filtering in Media uploader according to custom post type
- How to upload imagick resource to media in wordpress
- How do I create Comma Separated list of attached image ids?
- Remove image from post also removes photo from media library
- I need a Simple image uploader with a simple screen. WP default has too many options.
- All my inserted images gets a link to the full image even if it is already full size image
- Multisite media library uploads broken images
- Different upload path per file type
- Frontend Post Form Validation
- Remove permalink from images when inserting into post
- Adding Attachment Display Settings in custom media frame
- limit file type and file size using media_handle_upload
- how can I put an image in a post with original size
- Find unused images?
- Comma separated all attached image ID numbers except featured image ID number
- Modify Image Source With The_Content Filter?
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- Featured Image uploaded, attached and set but only appearing in the media library
- Format the Layout of Images In The Edit Post Textarea?
- How can I create more upload paths, like a post corresponding to a post title folder used to store images of the same product
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Get all attachment by post excluding featured and content inside
- CF7 upload file failing [closed]
- Set Maximum Width for an uploaded image
- Upload media only to DB
- Get images attached to a specific page
- How to only publish posts with image in it
- Front end post submission form with duplicate type fields
- Is there a way in WordPress to convert images to WebP without a plugin?
- Replace image name on upload to the new post name on front-end form
- Display a mixed list of posts and media
- Posts page not showing correct image
- How can i identify media uploaded to my website that is not being used anywhere anymore?
- How to add “alt” attribute for image during upload at WP front-end?
- Author Avatar as default first image
- Only show featured image on exerpt and exclude images in post
- image URL changed in wordpress
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- Changing The Default Header POST Title and Description text by category in wordpress
- Serving Images from subdomain in wordpress
- Delete Post but retain image of post [WP REST API]
- Delete media from the post but keep my featured image and post
- WordPress append -1 to the image name
- Updated wordpress missing image upload area
- Modified core/image rendering not showing in posts – only on pages
- How to generate an HTML link automatically from URL in a users’ post
- how let users select categories for posts in frontend?
- Why does media_handle_sideload upload to last month’s folder?
- Zip all (original) images from media gallery
- Embed image in post from external url
- Post/Edit/Delete Post From Frontend… How?
- Bulk Attach Or Insert Media To Post Without Opening Post Editor
- How to add audio media in a post?
- Upload unnattached image from frontend
- Assign custom class to post content images
- How to automatically convert images to WebP on WordPress?
- Import alt text in set_post_thumbnail
- Search doesn’t display posts with images
- Inside post image title has been posting as a post title on my main post page
- Set Featured Image of a post