Hola,
Estoy siguiendo este tutorial en el blog de desarrollo de WordPress:
https://developer.wordpress.org/news/2023/03/creating-a-custom-block-that-stores-post-meta/
Tengo todo funcionando correctamente y el bloque captura y muestra correctamente el contenido dentro del bloque. El registro de los metadatos en la consola también muestra que el contenido del testimonio se está actualizando en la metamatriz, pero después de presionar guardar y actualizar la página, vuelve al valor original establecido en el cuadro del metacampo en lugar del valor establecido en el editor.
// Post Meta registration
register_post_meta(
'product',
'testimonial',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => 'wp_kses_post',
)
);// Post type registration
register_post_type(
'product',
array(
'labels' => array(
'name' => __( 'Products', 'tutorial' ),
'singular_name' => __( 'Product', 'tutorial' ),
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'supports' => array(
'title',
'editor',
'thumbnail',
'excerpt',
'custom-fields',
),
)
);// Edit.js code
export default function Edit( {
attributes: { authorName, authorURL },
setAttributes,
context: { postType, postId },
} ) {
const [ meta, updateMeta ] = useEntityProp(
'postType',
'product',
'meta',
postId
);const { testimonial } = meta;
return (
Testimonial goes here
tagName="span"
placeholder={ __( 'Author name', 'tutorial' ) }
allowedFormats={ [] }
disableLineBreaks
value={ authorName }
onChange={ ( newAuthorName ) =>
setAttributes( { authorName: newAuthorName } )
}
/>
tagName="a"
placeholder={ __( 'Author URL', 'tutorial' ) }
allowedFormats={ [] }
disableLineBreaks
value={ authorURL }
onChange={ ( newAuthorURL ) =>
setAttributes( { authorURL: newAuthorURL } )
}
/>
);
}¿Esta ya no es la forma correcta de recuperar y editar metacampos de publicaciones? ¿Alguien tiene algún código actualizado en alguna parte para esto si es así?
¡Gracias!