Comments on: How to Register Gutenberg Blocks for Some Custom Post Type only, using PHP (not JS!) https://www.designbombs.com/registering-gutenberg-blocks-for-custom-post-type/ Droppin' design bombs everyday! Fri, 27 May 2022 15:50:24 +0000 hourly 1 https://wordpress.org/?v=6.8.5 By: Hans Schuijff https://www.designbombs.com/registering-gutenberg-blocks-for-custom-post-type/#comment-138873 Fri, 27 May 2022 15:50:24 +0000 https://www.designbombs.com/?p=30786#comment-138873 I’d been looking for a way to solve this. In my own test I found the condition “post_type_exists( $_REQUEST[‘post_type’] )” failed at first.

Plugins may use the init hook to register_post_type too and the order of callback execution is than an issue. In my case it was the events calendar that made it fail. Easy to solve, of course, by adding a higher prio, but one needs to think of it.

Perhaps the “post_type_exists( $_REQUEST[‘post_type’] )” condition also isn’t that important, since it will only be used to match my cpt in order to decide if the block is allowed.

Not sure when the post_id query var is used (legacy cases?), but the code works for me like this, so thanks for sharing this solution.

]]>