Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
How to get current post id in Gutenberg custom block?

This is my block.js file. In 4th line, I have MediaUpload var, Under it I want current post id. How can I get it?

( function( blocks, editor, i18n, element, components, _ ) {
var el = element.createElement;
var RichText = editor.RichText;
var MediaUpload = editor.MediaUpload;

blocks.registerBlockType( 'gutenberg-examples/example-05-recipe-card', {
    title: i18n.__( 'Author card', 'gutenberg-examples' ),
    icon: 'index-card',
    category: 'layout',
    attributes: {
        writer: {
            type: 'array',
            source: 'children',
            selector: 'h2',
        },
        photography: {
            type: 'array',
            source: 'children',
            selector: 'h2',
        },
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The current postId is accessed by the block context by adding usesContext when registering the block type, eg:

blocks.registerBlockType( 'gutenberg-examples/example-05-recipe-card', {
    title: i18n.__( 'Author card', 'gutenberg-examples' ),
    icon: 'index-card',
    category: 'layout',
    attributes: {...},
    usesContext: [ 'postId' ]
});

By including context in your edit({attributes, setAttributes, context}) function, you will have access to the current postId with:

edit({attributes, setAttributes, context}){    
    const {postId} = context;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda