Adding featured image via PHP

Currently I’m working on a project where site is driven by user articles, how it works:

  1. Any user goes to compose post page
    and writes post along with few
    details, has upload file option for
    image and then submits
  2. Post is uploaded in wordpress and the image attached is set as featured image
  3. Admin approves the post and it gets published.

Here user is not required to have an account. I am using wp_insert_post to create a new post but not able to figure out how to add featured image via PHP.

Related posts

Leave a Reply

1 comment

  1. Use the set_post_thumbnail function.

    set_post_thumbnail( $post_ID, $thumbnail_id );
    

    Require you use WordPress 3.1.0 or later.

    You need call this function after you have successfully created your post via wp_insert_post and have a valid $post_ID.