Title: How To Update Featured Image Programatically
Last modified: April 18, 2020

---

# How To Update Featured Image Programatically

 *  [jackrobson](https://wordpress.org/support/users/jackrobson/)
 * (@jackrobson)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/how-to-update-featured-image-programatically/)
 * Hello fellow WordPress enthusiasts,
 * I thought I’d be able to update the featured image using this code…
 * `wp.data.dispatch( 'core/editor' ).editPost( { featured_media: 10 } );`
 * However, I get an error:
 * `Uncaught (in promise) Error: The entity being edited (postType, undefined) does
   not have a loaded config.`
 * What needs to be changed?
 * Regards,
    Jack

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

 *  [Brijesh Dhanani](https://wordpress.org/support/users/brijeshdhanani/)
 * (@brijeshdhanani)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/how-to-update-featured-image-programatically/#post-12699516)
 * You need to retrieve data before change it. I have added the code below. You 
   can check it:
 * `wp.data.select( 'core/editor' ).getEditedPostAttribute( 'featured_media' );`
 * After retrieving data you can dispatch action for updating the post.
 * `wp.data.dispatch( 'core/editor' ).editPost({ featured_media: 10 });`
 *  Thread Starter [jackrobson](https://wordpress.org/support/users/jackrobson/)
 * (@jackrobson)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/how-to-update-featured-image-programatically/#post-12701400)
 * Nope that code produces same error.
 * Interestingly,
 * `wp.data.select( 'core/editor' ).getEditedPostAttribute( 'featured_media' ) =
   == undefined`
 * Despite their being a featured_media item set.
 * Does anybody know how to change ANY value inside the edit post window?

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

The topic ‘How To Update Featured Image Programatically’ is closed to new replies.

 * ![](https://ps.w.org/gutenberg/assets/icon-256x256.jpg?rev=1776042)
 * [Gutenberg](https://wordpress.org/plugins/gutenberg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gutenberg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gutenberg/)
 * [Active Topics](https://wordpress.org/support/plugin/gutenberg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gutenberg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gutenberg/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [jackrobson](https://wordpress.org/support/users/jackrobson/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/how-to-update-featured-image-programatically/#post-12701400)
 * Status: not resolved