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

313
Visualizações
How Can i get the Post featured image in Gutenberg block

I'm creating a custom Gutenberg block to fitch the a CPT grid .. and I want to get the featured image for each post .. how can I call it and fitch it in save function .. this is my edit code

   edit: withSelect((select) => {
      var query = {
        per_page: -1, // set -1 to display ALL
        exclude: 50, // or pass multiple values in an array, e.g. [ 1, 9098 ]
        parent_exclude: 43, // or [ 43, 44, 98 ]
        orderby: "date",
        order: "asc",
        status: "publish", // or [ 'publish', 'draft', 'future' ]
        categories: [5, 10, 15], // category ID or IDs
        tags: 4, // tag ID, you can pass multiple too [ 4, 7 ]
        search: "search query",
        _embed: true,
      };
      const posts = select("core").getEntityRecords("postType", "post", {query});
      let media = {};
      posts?.forEach((post) => {
        media[post.id] = select("core").getMedia(post.featured_media);
      });
      return {
        posts,
        media,
      };
    })((props) => {
      const { media, posts } = props;

      if (!posts || !media) {
        return <p>Loading...'</p>;
      }

      return (
        <ul>
          {posts.map((post) => {
            if (media[post.id]) {
              const imageThumbnailSrc =
                post &&
                post._embedded &&
                post._embedded["wp:featuredmedia"].size.thumbnail.source_url;
              return (
                <li>
                  <img src={imageThumbnailSrc} />
                  <a href={post.link}>{post.title.raw}</a>
                </li>
              );
            }
          })}
        </ul>
      );
    }),

And There's No Error Shown in Console it just shows only the title and link!

about 4 years ago · Juan Pablo Isaza
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