You’ll want to take a look at wp_insert_attachment
and wp_generate_attachment_metadata
.
You can’t insert a featured image/thumbnail using the_post_thumbnail
– that function only gets the thumbnail for the current post.
See: http://codex.wordpress.org/Function_Reference/wp_insert_attachment
and http://codex.wordpress.org/Function_Reference/wp_generate_attachment_metadata
Related Posts:
- Redirect to another page using contact form 7? [closed]
- posts_per_page displays only 2 posts instead of 4 posts
- Can’t put a hyperlink on Featured Post’s Image
- Weird Behaviour: Not all WordPress Posts appearing
- How to modify this function to exclude also the post belonging to a specific category?
- How do I change/modify the_post_thumbnail(); html output?
- Build a content and excerpt grid loop with paging and options for # of posts
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- New Plugin Review
- Use template for posts with a particular category grandparent
- WP Insert Post function – Insert Post Thumbnail
- How to make thumbnail image fit into a div where image dimentions are completely different?
- How to Display Image Meta underneath EVERY image in EVERY post
- Use wp_get_recent_posts with search term
- Remove query string specific key value
- Hide post if matches current month and year
- How can I use wp_query to show all product data using just the products ID?
- Query all posts of a custom taxonomy term
- Trying to add attribute to my posts’ featured image
- Set the background to a default image if there isn’t a specified “featured image”
- Get post id in a function when edit/add a post
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Display a specific category of products in shop page and disable code for specific actions
- How to store post ID’s in cookie or session to display the same posts later
- Get users that likes the post
- Remove echo from shortcode
- Security for data obtained from the database
- Which PHP page is the Default Posts Page
- height should be set to auto to avoid pixelation in the post thumbnail function
- Display related posts without a plugin
- Function works everywhere, how to keep it to execute when creating a new post
- Pagination on Custom Post
- WP_Query: getting posts where custom field exists
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Array to string conversion on array_map
- Increment paged on WP_Query
- change the default order of posts only for specific categories
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- Custom query vars filters problem with pagination
- get post id from wp_insert_post for get_template_part
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- Else/If Statement to Display Photo Descriptions
- array_rand not working correctly?
- Error display post thumbnails for previous and next post
- WP_Query() load selected post
- How to get post category list as select in front-end?
- Fallback image URL if no featured image exists via a shortcode function
- How to pick “full/thumbnail” images in the loop?
- Displaying Event within two given time frames
- Get the alt text of the image in a array
- Wp Query : Order by distance lat,lon
- remove specificly the last tag in all posts
- Let current user know pending posts counts using wp_query
- Output product category link from WP_Query
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- “pre_get_posts” orderby custom date field in different format?
- How to exclude meta no index pages from wp_list_pages
- How to Send Pingbacks for all Posts in WordPress?
- wp_query – Exclude the first thumbnail from lazy loading on archives
- WordPress sorting posts by date and title using a dropdown
- WP query posts BUT show the most recent and one per author
- not outputting medium size image URL
- Ajax filter with loadmore button
- Query on a repeater date (acf)
- Delete post meta by serialized meta value
- How to put 2 php codes in functions.php without site crashing
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Send POST request to Flask app from functions.php file
- Getting info about selected posts using one WP_Query
- How to center all text body in single.php at once?
- Having trouble with customizing blog posts on the home page
- WP_Query To Display Product Of Brand On Taxonomy Page
- How to display last whole post on the homepage
- Custom Post type Ajax search results
- Getting page / post URL on publish and / or update
- Displaying POST content with HTML tags and all
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- How can I display a query in a page?
- Basic PHP question (displaying post title over thumbnail) [closed]
- Display Year and Month from custom field + Age Calculator
- Published custom posts missing
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- Insert wordpress tags below posts via functions.php
- Why does WP_Query show only the same post even with different categories and endwhile?
- Overwriting a Shortcode
- Trying to see if page is category or single and displaying title with appropriate heading tag
- How to get category pages to look like a certain archive page?
- add if statement to the featured image
- Remove default Image Sizes
- Add multiple HTML attributes to an Elementor button
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How do I get a function to work in single.php
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false