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

304
Views
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
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!