admin管理员组文章数量:1287504
In my edit()
function for a custom block I'm using the following to list my post titles and featured images:
import { useSelect } from '@wordpress/data';
edit( { attributes, setAttributes } ) {
// Request data
const data = useSelect((select) => {
return select('core').getEntityRecords('postType', 'post');
});
return (
<div { ...blockProps }>
{data &&
data.map( ( post, i ) => {
const featuredImage = post.featured_media ? wp.data.select('core').getMedia( post.featured_media ) : null;
return (
<div>
{ post.title.rendered }
{ featuredImage &&
<img src={ featuredImage.media_details.sizes.thumbnail.source_url } />
}
</div>
)
})
}
</div>
);
},
....
In the editor, this shows all my post titles but shows only a few featured images. When I click the block in the editor, all the other images appear as well. Why is this happening? I'm not sure what I'm doing wrong. I don't get errors.
本文标签: javascriptGutenberg getMedia() in post query doesn39t return all featured images
版权声明:本文标题:javascript - Gutenberg getMedia() in post query doesn't return all featured images 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741225190a2361725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论