Title: Featured Image: how to set using code?
Last modified: August 19, 2016

---

# Featured Image: how to set using code?

 *  [mark_weston](https://wordpress.org/support/users/mark_weston/)
 * (@mark_weston)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/featured-image-how-to-set-using-code/)
 * I’m using wp_insert_post to create a new post. This all works ok.
 * Does anyone know how to set the Featured Image – either using this function or
   another one?
 * Background: I’m using Contact Form 7 to capture some details & upload a file 
   and then using the before_send_mail hook to create the post.

Viewing 1 replies (of 1 total)

 *  [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * (@ambrosite)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/featured-image-how-to-set-using-code/#post-1625689)
 * The featured image is just a special case of an attachment image. The code that
   does it is in wp-admin/admin-ajax.php around line 1508 (search for ‘set-post-
   thumbnail’).

Viewing 1 replies (of 1 total)

The topic ‘Featured Image: how to set using code?’ is closed to new replies.

## Tags

 * [featured image](https://wordpress.org/support/topic-tag/featured-image/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/featured-image-how-to-set-using-code/#post-1625689)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
