Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
setMeta en el bloque gutenberg guarda el valor meta en varias filas en lugar de una fila

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; } })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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', )); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!