• jackrobson

    (@jackrobson)


    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

    (@brijeshdhanani)

    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

    (@jackrobson)

    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.