All current data from the Block Editor is stored in a data store. If you click on the save button, this data is send via the REST API to the database.
You can select data from the store and subscribe to changes.
// Create a higher-order component that updates automatically when featured image changes.
const applyWithSelect = withSelect( ( select ) => {
const { getMedia } = select( 'core' );
const { getEditedPostAttribute } = select( 'core/editor' );
const featuredImageId = getEditedPostAttribute( 'featured_media' );
return {
media: featuredImageId ? getMedia( featuredImageId ) : null,
featuredImageId,
};
} );
export default compose( [
applyWithSelect,
] )( MyCustomBlockEdit );
Related Posts:
- Auto-retrieve YouTube Image for Thumbnail?
- Hide gutenberg option blocks
- Disable block from editor based on post type
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- A good way to add a different background image for each page?
- Gutenberg gallery hook errors
- What is the best filter where to use register_block_type?
- @wordpress/hooks use to add actions/filters within multiple plugin
- WordPress hook that gets featured image from direct URL?
- How to extend custom (non-core) blocks?
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- WordPress How to reorder Page/Post Settings
- Add a Call to Action Button to WordPress Post Thumbnail
- Are there Hooks for featured image popup?
- How To Apply Different Styles To All Blocks Based on Post Meta Value?
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- How to set Post ID from context to an attribute in child block of Gutenberg Query Loop
- Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend
- The enqueue_block_assets is changing the styles of the editor interface
- Unable to trigger a frontend @wordpress/hooks action
- Replacing specific Gutenberg blocks
- How to hook update_post_meta and delete_post_meta?
- Are there any hooks that alter the 404 logic?
- Use wp init hook to call other hooks?
- Set default image link target in Gutenberg image block
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- Add_action to wp_head via functions.php
- Hook that fires when admin setting is saved
- Is there a hook which fires after all thumbnails are generated?
- What is the difference between update_post_meta and update_postmeta hooks?
- How to remove action hook done in a plugin from functions.php in my theme?
- Hooks for trashing, deleting, saving, restoring custom post type
- Implementing advanced add_* function wrappers
- My add_action (wp_footer, ‘method’) is not calling?
- Hook into wp_head(); in a plugin
- Use $query->set multiple times with pre_get_posts?
- How can I hook into the post editor title field in order to change the HTML?
- Can’t get ID of post that relates to the comment
- Searching hook to set cookies before and avoid “headers already sent”
- Hook before inserting user into database [duplicate]
- wp_redirect() not working on form submission with init hook
- WooCommerce – Overwrite action hook [closed]
- Admin Hook at the Login Page
- Which Hook? Hide attachments from specific post types in media library
- Custom action on login and “remember me”
- How to hook into Add New Member in BuddyPress
- Using wp_editor tinyMCE in metabox cause form alert on leaving page
- Hook when new CPT published AND postmeta inserted
- Need to check is_archive during init
- When WP_CLI runs WordPress from the command line, are hooks called?
- Query categories that have a description
- Gutenberg – Add align controls to a custom block
- Trying to run a compile command while saving post
- Action hook for custom tax edit
- wp cron job fires at every second or so, if callback is wrapped with DOING_CRON check it never fires at all
- Show message in media-new.php
- Hooks are not being removed in child theme
- Gutenberg Block – Post Featured Image Filter Hook
- add_action second argument missing
- How to get user meta fields that have just been updated?
- admin_notices action doesn’t trigger within save_post action
- When a plugin gets updated from the repo, does the “activation” hook fire again?
- Defining hooks within (php)classes?
- Divi hook not working [closed]
- Get terms of a taxonomy using useSelect
- Add WordPress hook outside of Plugin or Theme
- Add PHP code to header section from plugin
- How to change a WordPress term’s slug before saving
- dynamic add_action according to child pages (for homepage control)
- Remove action in a parent theme from the child theme
- Remove action within a class in a parent theme’s includes folder from the child theme
- Action hook save_post for newly created posts – $post object data is all empty
- add_filter to the_content from plugin function
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- Can not using get_header() cause trouble (later on)?
- Is there a author_update action?
- How to set Media Box form elements default value?
- How to get product information using hooks?
- Print additional fields in wp_new_user_notification_email_admin
- remove_action not working for a function
- Is there no concise way, a library maybe, to help with unhooking class functions and so on?
- Debug a WP install: how to find which functions write post updates during a process (a woocommerce checkout in my case)
- What hook should I use to add post meta data with on update?
- Problem with call_user_func_array front end
- How to I prevent WordPress from switching external HTTP links to HTTPS?
- Stylesheet is getting removed/deregistered automatically
- How to override get_avatar() function?
- Change user role if it’s orders count more than
- Featured image to grayscale with PHP imagefilter – which hook to use?
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- How to hook into publish_posttype?
- Custom filename when pasting an image from clipboard
- $GLOBALS & global doesn’t work [closed]
- How to display the category featured images [closed]
- Hooks not working on live server
- How to use useSelect to retrieve the currently default fontFamily?
- “Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter
- $wpdb->update not working as expected