you need to first create the post and get the id:
$postit = array(
'post_title' => $itemtitle,
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'items',
'post_author' => $user_ID,
'tags_input' => $the_post_id
);
$the_post_idit = wp_insert_post( $postit);
Once you have the post id you can use
update_post_meta( $the_post_idit,'_thumbnail_id',$itemimage);
just make sure that $itemimage holds the attachment ID.
Related Posts:
- Trying to add attribute to my posts’ featured image
- Display related posts without a plugin
- Automatically add images to a menu
- Error display post thumbnails for previous and next post
- How to pick “full/thumbnail” images in the loop?
- Having trouble with customizing blog posts on the home page
- Basic PHP question (displaying post title over thumbnail) [closed]
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- Unreadable pagination
- 200 Rewrite blog post links
- How to set a min number of words for a blog post
- PHP variable = get_the_post_thumbnail_url outputting without slashes
- Loop through categories and display posts title under each dropdown
- Get post id in a function when edit/add a post
- Is it possible to use Data URI image to set a post thumbnail?
- how do I get a specific post from a post with a subcategory in WP
- Automatically create child pages and grandchild pages when saving a (parent) page
- WP Post-Thumbnail
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Second transition_post_status hook fired instead of the first
- How to store post ID’s in cookie or session to display the same posts later
- Which hook/action will help me solve my problem?
- How can I add extra word in permalink when someone click download button?
- Post + form + action + results on the same page
- Open post-content in archive page in a Modal box with bootstrap
- Display custom post type title as text if post thumbnail is not available
- remove post that has no content
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Custom posts in different columns style
- Get children post mime type using parent post_ID wp_post
- How to show only subcategories in parent category not parent category?
- 404 error when I acess the second page of post-type
- Redirect to another page using contact form 7? [closed]
- post thumbnail, conditions, else wont work
- ‘Post-thumbnails’ feature does not seem to register
- Which PHP page is the Default Posts Page
- height should be set to auto to avoid pixelation in the post thumbnail function
- retrieve post data and insert it in seperate static html page without WordPress
- Three Questions with Twenty Eleven theme
- WP Insert Post and then go to post
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Returning data instead of echoing/printing
- Counting Search results, and displaying the offset per page
- Count posts on multisite with blog id
- Function works everywhere, how to keep it to execute when creating a new post
- Making (and edit existing) posts with ID included
- Copy taxonomy terms from one post to another programmatically
- WordPress function and string as variable?
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- Resize image to specific dimension (X to Y ratio)
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Update post title from external file?
- Parse error: syntax error, unexpected end of file
- Apply class to every third list item? [duplicate]
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Load Posts on Click via Ajax into a DIV
- How to catch wordpress post ID when it’s published
- set post limit at load more ajax wordpress
- WordPress query undefined offset in loop
- Find Site ID From WP_Post
- WP_Query: getting posts where custom field exists
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Only show first image in foreach loop
- Using featured image of blog archive page
- if custom field doesn’t exist, use post thumbnail instead, as image background
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- Do I need to edit my theme in order to change the title of my blog page?
- Add new post in existing categories using wp_insert_post
- WordPress upload file size error even after raising php limits
- How do I add more options to the post-new.php page?
- get post id from wp_insert_post for get_template_part
- Help Fallback (thumbnail)
- create front-end users post list by specific category
- Incrementing PHP variable onclick to display posts by month
- Modify main query before it run without pre_get_post
- Displaying list of posts in category page
- .html end of URl affected to SEO?
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- Get the id of all images in a post
- Get featured image with custom size outside WordPress
- How to add post thumbnail dynamically using Jquery?
- Displaying content on posts page based on category
- Do not duplicate posts with multiple categories in multiple loops
- how to make an array of post id’s in is_single
- Else/If Statement to Display Photo Descriptions
- Loading Posts & Category with Ajax
- Four posts per row [closed]
- array_rand not working correctly?
- Update if post with specific title exists