最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Create Page with Pagetemplate and get a post_type_object->template

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

There 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.

发布评论

评论列表(0)

  1. 暂无评论