我一直在尝试附加多个页面,eash到其页面模板使用foreach循环。。。手动意味着编写每个页面的代码可以工作,但在foreach循环中它无法工作。
我有几个这样的foreach循环,所以我不想手动执行,也希望了解/理解问题。。。这是我的密码
请注意,只需添加带有值的自定义字段即可。。(奇怪)我做错了什么。
$start_number = 2;
$iim_pages = array(\'tools\', \'clients\', \'users\', \'resources\', \'data\', \'data2\', \'settings\');
foreach($iim_pages as $page) {
$page_title = ucwords(str_replace(\'-\', \' \', $page));
$page_filename = \'page-\'.$page.\'.php\';
//don\'t change the code bellow, unless you know what you\'re doing
$page_check = get_page_by_title($page_title);
$new_page = array(
\'post_type\' => \'page\',
\'menu_order\' => $start_number,
\'post_title\' => $page_title,
\'post_content\' => \'\',
\'post_status\' => \'publish\',
\'post_author\' => 1,
);
if(!isset($page_check->ID)){
$new_page_id = wp_insert_post($new_page);
// DOESENT WORK WITH ADD_POST_META or UPDATE_POST_META
add_post_meta($new_page_id, \'_wp_page_template\', $page_filename);
// THIS WORKS!
add_post_meta($new_page_id, \'testmeta\', $page_filename);
}
$start_number++;
}