Estoy escribiendo un bloque de gutenberg que guarda los datos en metacampos. El problema es que el valor se guarda en varias filas en la base de datos en lugar de una. ¿Cómo puedo guardar en una fila?
Por ejemplo: 'Mi manzana' se guarda como metakeyname: My y metakeyname: apple en la base de datos. Quiero guardarlo como metakeyname: Mi manzana
A continuación se muestra mi código. Por favor ayuda. ¡Gracias!
const { __ } = wp.i18n; const { registerBlockType } = wp.blocks; const { RichText, PlainText, MediaUpload, InspectorControls } = wp.editor; const { TextControl, Tooltip, PanelBody, PanelRow, FormToggle, Button } = wp.components; const el = wp.element.createElement; registerBlockType('my/fields', { title: 'My Fields', description: 'Fill in the required data and press the Update button above', icon: 'products', category: 'common', attributes: { sku: {type: 'string'}, pdf: {type: 'string'}, gallery: {type: 'string'}, features: {type: 'string'}, brands: {type: 'string'}, category: {type: 'string'}, }, edit: (props) => { const { attributes, setAttributes } = props; const [meta, setMeta] = wp.coreData.useEntityProp('postType', 'post', 'meta'); return el( "div", null, el( "h3", null, "Please enter Product name above & details below" ), el(TextControl, { label: "SKU:", value: attributes.sku, onChange: (newtext) => setAttributes({ sku: newtext }) & setMeta({sku: newtext}) }) ); }, save: function(props) { return props.attributes.sku; } })Finalmente lo conseguí. Tuve que definir single = true y type mientras hacía que el campo en particular estuviera disponible en el resto de la API.
// Meta in REST API add_action( 'rest_api_init', 'my_register_meta_fields'); function my_register_meta_fields() { register_meta( 'post', 'sku', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', )); }