我正在以编程方式插入一个新页面,然后我想使用该新页面的ID添加模板,但是wp\\u insert\\u post没有返回任何ID,下面是我使用的代码
$tittle = \'My new page\';
$newPage = array(
\'post_type\' => \'page\',
\'post_title\' => $tittle,
\'post_status\' => \'publish\'
);
$post_id = wp_insert_post( $newPage);
print_r($post_id);
实际上,我是这样使用代码的function criar_pag($titulo, $template = 0){
$a = get_page_by_title( $titulo, \'post\' );
if ($a == null || $a->post_status == \'trash\') {
$pagina = array(
\'post_type\' => \'page\',
\'post_title\' => $titulo,
\'post_status\' => \'publish\'
);
$post_id = wp_insert_post( $pagina);
update_post_meta($post_id, \'_wp_page_template\', $template);
}
}
criar_pag("my new page", "customtemplate.php");