First you’ll need to upload the image, like this. This will upload the image and add a row to wp_posts
where your attachment is.
How dynamic do you need this to be? Can you upload the image with the user interface or does that have to be done programatically as well?
In your case, the third parameter of update_post_meta()
should be the ID of the image in the wp_posts table.
Edit: This is more what you need regarding the image upload: How to add image to post programmatically?.
Related Posts:
- Front end post or photo or both
- add_image_size() for specific Post Types
- How to disable generation of default image sizes for some custom post types?
- Make featured image required
- set_post_thumbnail_size in percent, not pixels?
- add_image_size for post type
- Change post featured image on hover
- is there a way to retrieve posts that do not have a featured image assigned?
- Custom Image Thumbnails of Different Sizes
- Link to full size post thumbnail
- Multiple featured sizes / images / excerpts
- Redirect to another page using contact form 7? [closed]
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- Auto post creation
- Dynamic pages for linked categories and content
- Using Image Sizes for Custom Post Types outside the Loop
- link featured image to external link
- Thumbnails Not Generating
- i need to have a tab with gategory post
- Links Image in “Catalog” Page to Posts
- How To Loop Through list with Custom Post Types
- set_post_thumbnail or media_sideload_image adds image multiple times in media library
- How to Create Grey Background for Product Images on Website Display but Retain White Background on Downloaded JPGs?
- List all images from a single post meta value
- Displaying media for custom post type
- Show featured image next to post-teasers in Genesis Framework?
- Remove rows in the manage post/page view
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- How to create custom boxes with text inside?
- How to change post featured image using a custom field of category?
- How to add post_type=value when editing that post type in the WordPress admin?
- Force documents to appear in Featured Image dialogue
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Open Custom Post Type as PDF
- Using The REST API How To Pull All Custom Posts?
- Change Featured Image / Thumbnail CMS Description
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Featured Images does not show in custom post type
- Loading custom post thumbnail into stream
- Is it possible to show full content of the post when there is only one post in a grid?
- How to move image thumbnails into custom folder for custom post type
- Show the same Article Available in Other Categories
- Getting posts under the custom post type ui category
- Storing posts from query and accessing later via AJAX call
- If post has custom field then display css-class
- Display only one post each WEEK
- How to set YouTube video as featured image?
- List children on child post
- uploading images to specified directories
- Restrict custom post type from appearing with ?post_types=
- Show custom post type filtered by category
- create parent post using wp_insert_post
- Get image post ID in media upload
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- How do I do this with WordPress? Taxonomies?
- Errors when uploading images in WP 3.5
- Hide editor while keeping add media button in custom post type
- Disable block with taxonomies at post page
- Custom Post Type with image gallery
- I would like to have different styles for my posts based on the content of each post
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- How to Create an Image Upload Box for Custom Posts?
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Display Ad on Specific Categories
- Hiding posts by other users and non-logged in
- Add custom image size for custom post type or taxonomy
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- Add custom post type settings to wordress default posts
- Set size for attachments
- How to automatically set ‘default image size’ for specific Custom Post Type
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- JS innerhtml changing style when using AJAX
- Show titles, date of all posts on single category page
- Side effects of Script and Iframe in post
- How to change the post type a theme shows by default?
- Set a checkmark in a category based on a URL-parameter
- Several post types on WP Query by tag and taxonomy
- No Permission to add new Page, Post or CPT with Admin role
- Update postmeta Parent when post_status child change
- custom post type category count shortcode
- Portfolio Page for Classic Posts
- Add post location with mile radius allowing search
- Get the category from custom post type
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Set up post page like JAMA articles
- Custom Post Slug same as Parents Category Slug
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site