Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

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.

share|improve this answer
    
Its alright. I found that sending the thumbnail URL was in the end easier –  Robin I Knight Feb 23 '11 at 14:09

This sends the thumbnail URL as a custom field. It is what I used in the end.

$itemimage = wp_get_attachment_url(get_post_thumbnail_id($itemID));

__update_post_meta( $the_post_idit, 'productimage', $itemimage); 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.