Use the set_post_thumbnail function.
set_post_thumbnail( $post_ID, $thumbnail_id );
Require you use WordPress 3.1.0 or later.
You need call this function after you have successfully created your post via wp_insert_post
and have a valid $post_ID
.
Related Posts:
- How to upload imagick resource to media in wordpress
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- Get featured image with custom size outside WordPress
- How to Make Thumbnail of Post Stay Animated
- I can’t set image ad fatured programatically
- Generate and upload screenshot as featured image for user-submitted post
- What’s the best way to use the Featured Image for responsive web design?
- Uploading media with the REST API
- Adding a custom image upload size and making it selected by default?
- Image Upload “exceeds the maximum upload size for this site”, but php.ini is correct
- Failed media upload: “The uploaded file was only partially uploaded.”
- Create Image Uploader for Widget
- How to resize image on client-side before upload?
- Adding Featured Image to Post programatically
- Specified file failed upload test. wp_upload_handle
- How to add a featured image to a existing post via php?
- Is it unsafe to put php in the /wp-content/uploads directory?
- How to use SRCSET with get_the_post_thumbnail()?
- Image upload via FTP to wordpress media library
- WordPress media upload “HTTP error”
- How do I get images (with a thumbnail preview) to show in search results?
- Restrict WordPress File Type Uploads by User Type
- Modify Maximum upload file size text
- How to get Poster (thumbnail) Image of Video
- Upload a json file in php [closed]
- Custom image upload
- How to scale image with equal width and height without distortion?
- Featured image fallback link to permalink
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- Echo URL of large version of Featured Image
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- how to retrieve uploaded url of zip files
- Why is $_REQUEST an empty array in admin-ajax.php?
- Randomly Assign an Image’s Alt Text Based on Data From Post
- WP dynamic featured image – Can’t get second featured image url
- Is it possible to use Data URI image to set a post thumbnail?
- WP Post-Thumbnail
- How to upload a file to a folder named after the user_id via plugin
- Upload multiple images to a Woocomerce product
- Display custom post type title as text if post thumbnail is not available
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Upload file could not be moved to wp-content/uploads
- NGINX rewrite rules for multisite
- Change WordPress Upload Folder using wp handle upload
- How do I Import / Upload Files with jQuery AJAX?
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- zip unzip attachments in wordpress
- Apply class to every third list item? [duplicate]
- WordPress upload file size error even after raising php limits
- Get uploaded image and attach it to the new post
- Help Fallback (thumbnail)
- How to add post thumbnail dynamically using Jquery?
- Why is my max_upload_filesize being limited to 2M? [duplicate]
- Images Uploaded saving onto older/previous year folders
- How do I increase the upload size only when editing special pages?
- How to set a featured image (thumbnail) with PHP?
- Convert canvas to image and upload image to server
- How to change thumbnail src attribute?
- How to get the filename from file system and create a download link?
- Error display post thumbnails for previous and next post
- Get the featured image url of clicked post
- Fallback image URL if no featured image exists via a shortcode function
- How to pick “full/thumbnail” images in the loop?
- Get the alt text of the image in a array
- Convert all uploaded PNG files to PNG-8 format
- How to decrease the max file upload size without using php.ini or htaccess?
- Some problems in custom widget
- Checking page before applying image restrictions while uploading
- Change image data durgin upload
- Hook on file upload
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- wp_query – Exclude the first thumbnail from lazy loading on archives
- Replace background image with post thumbnail in shortcode
- How to add WordPress Featured image in tag ..?
- Sudden Upload HTTP errors, PHP uploads and memory limits are already to high to my taste. Anything else?
- How to programmatically set existing image in media library the featured image for a post in wordpress
- How to link featured images in single.php for only non-logged-in users?
- Thumbnail wouldn’t scale to size properly
- I want url from a file in media using title file
- Crop an image after upload on custom account page
- media_handle_upload fails with gravity form submitted image
- Restrict File Type Uploads by User on Wordress via functions.php
- wp_delete_attachment not working with multiple values
- Can’t put a hyperlink on Featured Post’s Image
- add class to background image
- News and Featured image
- How to correctly add the featured immage (thumbnails) support in a WP theme? Why I can’t add a featured immage?
- WordPress will suddenly stop saving files uploaded by my code (ran in nopriv ajax)
- Overwriting a Shortcode
- Post Thumbnail on Single (if elseif else)
- Name Input from widget displays Sidebar name instead of saved data
- the_post_thumbnail unless video id is added
- File Upload with Server in safe_mode
- Edit Image/Image Details – Replace button missing
- Correct Syntax for uploading files to custom directory in WordPress
- add if statement to the featured image
- Pull latest Youtube Video from json url and make new post
- WordPress directories not writable after PHP version upgrade