Title: Programmatically setting featured image
Last modified: August 19, 2016

---

# Programmatically setting featured image

 *  [Warren Harrison](https://wordpress.org/support/users/hungrymedia/)
 * (@hungrymedia)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-setting-featured-image/)
 * I know I can get a post’s featured image using get_the_post_thumbnail() but how
   would I go about programmatically **setting** a post’s featured image in a plugin.
   After looking through the data in the wp_posts and wp_postmeta tables, I can 
   see no difference between an image embedded within a post and one set as a featured
   image.
 * Any help is greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Inigo Gonzalez](https://wordpress.org/support/users/inigoini/)
 * (@inigoini)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-setting-featured-image/#post-1708524)
 * The only way I found is to insert a post meta with the key _thumbnail_id.
 * for example: `add_post_meta($post_id, '_thumbnail_id', $attachment_id);`
 * Hope this helps
 *  Thread Starter [Warren Harrison](https://wordpress.org/support/users/hungrymedia/)
 * (@hungrymedia)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-setting-featured-image/#post-1708533)
 * aha! I will give that a whirl. Thanks so much for the info.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Programmatically setting featured image’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Warren Harrison](https://wordpress.org/support/users/hungrymedia/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/programmatically-setting-featured-image/#post-1708533)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
