Whilst performing wp_insert_post, how would one insert the post thumbnail. I tried the code below to no avail.

$postit = array(
    'post_title' => $itemtitle,
    'post_content' => '',
    'post_status' => 'publish',
    'post_type' => 'items',
    'post_author' => $user_ID,
    'tags_input' => $the_post_id,
    'post_thumbnail' => $itemimage,

);
 $the_post_idit = wp_insert_post( $postit);

Any ideas,

Marvellous

2 Answers
2

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.

Leave a Reply

Your email address will not be published. Required fields are marked *