admin管理员组文章数量:1328337
Trying to get latest 10 posts to display in a Gutenberg plugin, but I can't figure out how to access the latest posts from the block.js. I know how to do it from PHP and it's easy, but this is new to me. Do I have to make a request to the REST API or is there a better practice?
Trying to get latest 10 posts to display in a Gutenberg plugin, but I can't figure out how to access the latest posts from the block.js. I know how to do it from PHP and it's easy, but this is new to me. Do I have to make a request to the REST API or is there a better practice?
Share Improve this question asked Jul 14, 2020 at 15:55 Stephen SabatiniStephen Sabatini 2363 silver badges13 bronze badges 1 |1 Answer
Reset to default 3You'll need to use the REST API. You can access the latest posts by calling:
wp.apiFetch( { path: '/wp/v2/posts' } ).then( posts => {
console.log( posts );
} );
Here is some more information on using the package - https://developer.wordpress/block-editor/packages/packages-api-fetch/
本文标签: How to grab posts in Gutenberg Block
版权声明:本文标题:How to grab posts in Gutenberg Block? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742260201a2442370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp.api
developer.wordpress/rest-api/reference/posts in this casewp.api.posts
, I'm about to test this myself – Caleb Jay Commented Oct 17, 2022 at 5:40