If you need to distinguish between post types in a block editor script, you can use the following code to get the post type:
wp.data.select('core/editor').getCurrentPostType()
Code language: JavaScript (javascript)
If you need to distinguish between post types in a block editor script, you can use the following code to get the post type:
wp.data.select('core/editor').getCurrentPostType()
Code language: JavaScript (javascript)
This doesnt work. it gives NULL
In what context are you running the code? Works fine for me inside
registerPlugin()
.By the way: In widgets, getCurrentPostType() returns null.
Oh, yes, that makes sense, thanks for the comment!