André Amorim

Crafting Web Experiences


//

Get post meta when building a Gutenberg Block

import {
  PanelRow, TextControl,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useEntityProp } from '@wordpress/core-data';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { registerPlugin } from '@wordpress/plugins';

function CustomMetaPanel() {
  const postType = useSelect(
    (select) => select('core/editor').getCurrentPostType(),
    [],
  );

  const [meta, setMeta] = useEntityProp('postType', postType, 'meta');
  const metaValue = meta.customMeta;
  const updateMetaValue = (newValue) => {
    setMeta({ ...meta, customMeta: newValue });
  };
  return (
    
      
        
      
    
  );
}

registerPlugin('plugin-name', {
  render: CustomMetaPanel,
  icon: '',
});

Published date:

Modified date: