set_post_thumbnail()
requires the second parameter to be an int
for attachment id
, so the statement $res2 = set_post_thumbnail( $new_ID, $file_name);
does not work.
First you need to add the image to your database as an attachment and then you will be able to use its id
to set it as thumbnail.
See this example for more help and detail to set an image as featured image.
Related Posts:
- How to Fix HTTP Error When Uploading Images?
- Minimum Dimensions Requirement for Featured Image?
- Add Image Dimensions to Media Library Tab on Media Upoader
- Custom post type thumbnail / Media Library WP_DEBUG notice [closed]
- Use wp_remote_get to add image to media library
- Replicate featured image functionality
- Need clear explanation about medias/files/attchments
- How to replace featured image upload option with the post media image option
- media-library: how to insert thumbnails with a fixed width, regardless of landscape/portrait orientation
- How to bring files from the upload directory to the media gallery?
- WordPress image crop probems
- Images uploaded on frontend display correctly but not in media editor.
- Thumbnail (featured image) and Media Library cleanup queries help needed
- After migrating media library is not showing thumbnails
- How to modify Media Library images DPI [ image quality down to make small in size ] [closed]
- How do I regenerate thumbnails?
- Add Title Attribute to WordPress Image the_post_thumbnail
- Replacing Gutenberg Featured Image control?
- oEmbed, thumbnails and wordpress
- the_post_thumbnail scaling not hard cropping
- Featured Image Inherited from Parent Page
- Change wording of default thumbnail metabox
- Specific featured image for each category
- how to pull images with no add_theme_support(‘post_thumbnails’)
- Can WordPress crop only the post thumbnails?
- Query the post which have a thumbnail
- How to show a featured image as current?
- How can I get a different image size, if all I have is the link?
- Show current page featured image in sidebar
- Importing featured image to posts, duplicates the image
- How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
- Images are randomly deleted from server
- Use post thumbnail as div background
- How do I set the default “feature image” size?
- Featured Image missing in WordPress 3.2 Admin
- Change post thumbnail using front end post edit form
- Featured image thumbnail sometimes in content, sometimes changes header images
- Function to replace the url of featured images in the wordpress database?
- has_post_thumbnail gives always TRUE
- Displaying wordpress image size as array used for page builder
- Setting a default placeholder image WITHOUT link
- If I Regenerate Thumbnails, would WordPress delete the existing Thumbnails and replace them with ‘new copies’?
- how to use first post image as thumbnail on wordpress
- Make the first image the post thumbnail without setting it as the featured image
- set a chosen image-file-input as a featured image from wp frontend
- offload media to external services [closed]
- Aligning the thumbnail image
- How do get post thumbnail into plugin?
- Default Featured Image from Post content
- upload or auto setup feature photo by user avatar
- How to create resized versions of images added with wp_insert_attachment
- Can I insert the feature image inside the content, after any paragraph?
- Set Post Thumbnails in Percents
- WordPress returns old thumbnail size after changing media settings
- get_the_post_thumbnail() returns nothing?
- Image with large file size not cropping
- What can I do if I set a gif as featured image? no thumbnail when i share on facebook
- Can’t get post thumbnail to display in foreach loop
- Child Category Image
- Resizing thumbnails retrospectively
- upload image only
- How Do I Create A WordPress Secondary Featured Image Without A Plugin? [closed]
- Generating very small sized thumbnails from featured image
- a tricky question about featured image
- Where to add the_post_thumbnail( )
- Is wordpress compressing my images? if so, how to prevent it?
- Getting featured image with direct $wpdb within plugin
- WordPress get_categories & listing recent post thumbnail
- Edit Media – Edit Custom Sized Featured Images
- set_post_thumbnail_size not cropping featured images
- Making featured image to show on home page
- Multi post thumbnails doesn’t return anything
- Add filter on certain thumbnail sizes only
- WordPress featured image url rendering incorrectly when page is loaded causing image to break
- Where in functions.php to add this code so thumbnail images display?
- Adding thumbnails independent of images in blog posts
- Featured image size per post type
- display div tag only if post has thumbnail
- How to exclude 150*150 Image to set as a thumbnail?
- Get featured image from post on RSS feed
- Issue with wordpress thumnails – same thumnail displayed everywhere
- Usage of add_image_size (for featured image)
- Featured image: Dynamic image sizes when enlarged with javascript
- Smaller Size for featured images
- Featured image doesn’t appear in Blog index
- Remove Featured Image based on Date
- How to show only 2nd featured img on home/blog
- Echo recent posts each with its own respective featured image
- How to get post thumbnail to be equal to set media size
- Add notice to add image popup
- Mass/Bulk assign featured images to posts
- setting featured image is not working while running script in background, works when running that script from browser
- How to modify responsive images in post thumbnails
- get_the_post_thumbnail() – Invalid argument supplied for foreach() in /wp-includes/post-thumbnail-template.php on line 64
- Different thumbnail size than actual picture in post
- How to get the featured image inside of a single-.php template?
- Where is the template from the_post_thumbnail()?
- Get Post Thumbnail Outside of Loop
- Theme:Twenty Fourteen, How to remove featured image on single post page for particular category
- Hot to change resized image link on posts