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

  • Looks like this is the correct answer. However, you need to realise that if you call this function in your script it will most likely return null the first time because the result is fetched asynchronously. More info: github.com/WordPress/gutenberg/issues/…
    – Jules
    Nov 23, 2022 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.