我已经为wordpress创建了一个插件,可以根据需要自动发布页面 我的问题是将此页面格式化为特定模板
我需要在邮件页面自动插入数据库时,将Sidebar position
设置为已禁用,以便拥有一个全宽页面并隐藏page title
...此选项出现在仪表板,我可以逐个点击它们,但这必须是自动的,而不是手动的。
$my_post = array(
'post_title' => wp_strip_all_tags( $tituloFichaP1 ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 ),
'post_type' => 'page',
'post_parent' => $parentPost,
'page_template' => 'microsite',
'comment_status' => 'open',
);
wp_insert_post( $my_post );
顺便说一句,page_template属性('page_template' => 'microsite')
也不起作用。插入Te post但模板设置为默认值。
提前致谢!!!
答案 0 :(得分:3)
我只是通过你的代码,你做了一个简单的错误,在“page_template”中应该是你的模板的文件名(filename.php)而不是模板名称。对于前如果您的模板 microsite的文件名 microsite.php ,则代码将超出您的代码。
$my_post = array(
'post_title' => wp_strip_all_tags( $tituloFichaP1 ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 ),
'post_type' => 'page',
'post_parent' => $parentPost,
'page_template' => 'microsite.php',
'comment_status' => 'open',
);
wp_insert_post( $my_post );
希望这会对你有所帮助。