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
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- Upload file could not be moved to wp-content/uploads
- Enable custom logo upload if logo is not in header
- NGINX rewrite rules for multisite
- Attach previously uploaded image to post – current code has unexpected results
- How do I get around “Sorry, this file type is not permitted for security reasons”?
- Change WordPress Upload Folder using wp handle upload
- How do I Import / Upload Files with jQuery AJAX?
- Redirect to another page using contact form 7? [closed]
- WordPress automatically adds links to uploaded images
- post thumbnail, conditions, else wont work
- WordPress function when file is uploaded, deleted or edited
- ‘Post-thumbnails’ feature does not seem to register
- height should be set to auto to avoid pixelation in the post thumbnail function
- Can I get an email notification when media is uploaded to the media library?
- Three Questions with Twenty Eleven theme
- Display related posts without a plugin
- Blob file download problem
- WordPress function and string as variable?
- Resize image to specific dimension (X to Y ratio)
- zip unzip attachments in wordpress
- Apply class to every third list item? [duplicate]
- Automatically add images to a menu
- Upload multiple files in randomly generated folder using wp_upload_bits
- Using featured image of blog archive page
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- if custom field doesn’t exist, use post thumbnail instead, as image background
- 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
- Else/If Statement to Display Photo Descriptions
- 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 URL of Featured Image After wp_insert_post()
- Custom upload folder
- WordPress İmages Upload & Delete Error
- Get the featured image url of clicked post
- Fallback image URL if no featured image exists via a shortcode function
- Allow user to Upload image and manipulate it on the frontend
- custom plugin with upload files does not work
- How to replace URL protocol using PHP?
- Call featured image url
- How to pick “full/thumbnail” images in the loop?
- Generate responsive post thumbnails of same size
- Front end file upload returning wrong attachment url
- 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?
- Trying to change featured image from 180×180 to full width on home page
- Show different size featured images (the_post_thumbnail) for 1st, 2nd and 3rd posts?
- Some problems in custom widget
- Checking page before applying image restrictions while uploading
- Change image data durgin upload
- Hook on file upload
- Need to add a post’s featured image to a section on the frontpage
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- How can I update WordPress plugins or WordPress itself in all server?
- async upload not working when not logged
- Add Featured Image to Existing Post
- wp_query – Exclude the first thumbnail from lazy loading on archives
- WordPress loading all local images from specific directory?
- not outputting medium size image URL
- Replace background image with post thumbnail in shortcode
- Resize post thumbnail
- Trying to generate a CSS file in wordpress uploads folder
- How to put 2 php codes in functions.php without site crashing
- How to add WordPress Featured image in tag ..?
- Maximum file Upload
- WordPress generate images size after upload
- Sudden Upload HTTP errors, PHP uploads and memory limits are already to high to my taste. Anything else?
- Add a default style if no Featured image is selected
- Change upload URL by mime type
- How to link all featured images to custom url in single.php for only non-logged-in users?
- How to programmatically set existing image in media library the featured image for a post in wordpress
- Having trouble with customizing blog posts on the home page
- How to link featured images in single.php for only non-logged-in users?
- Right path for renaming a file in uploads folder
- Thumbnail wouldn’t scale to size properly
- I want url from a file in media using title file
- WordPress file upload
- Upload images from one server to an other in wordpress
- 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
- get_post_thumbnail_id returns a negative number
- wp_delete_attachment not working with multiple values
- Basic PHP question (displaying post title over thumbnail) [closed]