admin管理员组

文章数量:1317898

I want to show the list of all available custom post types in the settings of the block in admin. How can I do that? Later I want to show a dropdown with those post types which user can select and save.

I want to show the list of all available custom post types in the settings of the block in admin. How can I do that? Later I want to show a dropdown with those post types which user can select and save.

Share Improve this question asked Oct 22, 2020 at 19:09 Imrul.HImrul.H 1752 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

wp.data.select('core').getPostTypes() will show return an array of objects that represent each registered post type that is available via the REST API.

wp.apiFetch({path:'wp/v2/posts'}).then( res => console.log( res ) ); will retrieve the latest posts. You may want/need to update the parameters to suit your needs. See the docs for more details

本文标签: How can I list all custom post types in a block