How can I list all custom post types in a block

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.

1 Answer
1

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

Leave a Comment