5

What I am trying to do is to use specific Reusable Blocks, that are editable by certain admins in the back end, within block templates for custom post types. So if you register a CTP or edit the capabilities of standard post types, you can use them like:

    function create_add_post_types() {
    register_post_type( 'product',
    array(
      'public' => true,
      'capability_type' => 'page',
      'show_in_rest' => true,
      'template' => array(
            array( 'core/heading', array(
                   'placeholder' => 'Füge eine Überschrift hinzu',
                   'content' => 'Projektname - Stadt, Land',
                   'level' => 1,
            ) ),
        )
    );
    }
    add_action( 'init', 'create_add_post_types' );

..except that insteadt of a core block like the heading here a reusable block is called.

2 Answers 2

4

I actually found a solution myself by following the way a reusable block is registered in this stackexchange thread:

Reusable blocks are all stored in/as core/block and this block has the attribute ref which carries the post id of that block.

So, you can use

array( 'core/block', array(
 'ref' => [your block ID],
) ),

and the ID of every registered block is visible via the URL of that block at [your-wordpress]/wp-admin/edit.php?post_type=wp_block

0

You can call a reusable block as you call to any post type:

$args = array(
    'post_type' => 'wp_block',
...

OR

get_page_by_title( 'Your Title', OBJECT, 'wp_block' );
1
  • That's true, but how do you use this to refer to a reusable block in a CPT template like in the example?
    – Playnary
    Oct 15, 2020 at 12:37

Your Answer

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

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