I have created a page per Code with:
$my_post = array(
'post_title' => $mytitle,
'post_status' => 'publish',
'post_type' => 'page',
'post_name' => $myurl,
'page_template' => 'Agenden.php'
);
$ID = wp_insert_post( $my_post );
i also have a function in functions.php to do a $post_type_object->template = ...
on a 'page'; but this function does not run for pages done with code top;
My question: How to do a page per Code with pagetemplate (Agenden.php) and give this blocktemplates
I have created a page per Code with:
$my_post = array(
'post_title' => $mytitle,
'post_status' => 'publish',
'post_type' => 'page',
'post_name' => $myurl,
'page_template' => 'Agenden.php'
);
$ID = wp_insert_post( $my_post );
i also have a function in functions.php to do a $post_type_object->template = ...
on a 'page'; but this function does not run for pages done with code top;
My question: How to do a page per Code with pagetemplate (Agenden.php) and give this blocktemplates
Share Improve this question edited Jan 31, 2020 at 18:21 Pratik Patel 1,1111 gold badge11 silver badges23 bronze badges asked Jan 31, 2020 at 13:01 CheckpointCheckpoint 133 bronze badges1 Answer
Reset to default 0There are two completely different templates in WordPress - page templates and block templates. Your wp_insert_post
assigns page template, which must exist in your theme directory and should be properly created (see docs). WP will automatically detect and use it to render this page. This is in no way related to $post_type_object->template
.