Wednesday, November 23, 2022
HomeWordPress Developmentblock editor - Customized Submit Sort does not have template content material...

block editor – Customized Submit Sort does not have template content material when creating programmatically in PHP however does when created in WP Admin


I’ve created a default template for a CPT for instance…

// Outline template
$template = [
    [
        'core/heading',
    ],
];

// Register the CPT
register_post_type(
    'my_cpt',
    [
        // ...
        'template' => $template,
        // ...
    ]
);

If I am going into WP Admin and click on new then the block editor is pre-populated with a heading block. Nonetheless if I create a put up programmatically in PHP…

//
$post_data = [
    'post_status' => 'draft',
    'post_title'  => 'Test post',
    'post_type'   => 'my_cpt',
];

//
return wp_insert_post( $post_data, false );

The put up has no content material.

Is there a way I could make this work? I do not see a means of reusing my template. I can set post_content with parsed block knowledge from the editor however I do not know learn how to convert my template into precise blocks. I might slightly not need to handle the template in a number of locations so reuse is vital

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments