Created
June 2, 2023 09:17
-
-
Save phpbits/efa38bc29996363b19483aca28850251 to your computer and use it in GitHub Desktop.
Retrieving Post Meta Value in the Gutenberg Block Editor : https://jeffreycarandang.com/how-to-enable-read-and-update-post-meta-in-the-wordpress-block-editor-gutenberg/(opens in a new tab)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSelect } from '@wordpress/data'; | |
/** | |
* My Custom Block | |
*/ | |
const MyCustomBlock = () => { | |
const META_KEY = 'custom_post_meta'; | |
const meta = useSelect((select) => | |
select('core/editor').getEditedPostAttribute('meta') | |
); | |
const { [META_KEY]: customMeta } = meta; | |
console.log(customMeta); // Log the value into the browser console. | |
return null; // Return your block content here. | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment