我可能會混淆術語,因此我希望您能遵循。wordpress在添加時獲得術語標題
我有一個自定義後類型的「套餐」 我已創建名作所謂的能力「添加封裝類型」
當我添加類別我想用的標題插入新的頁面只有在「添加軟件包類型」時才能使用新類別。
我似乎無法用下面的代碼獲取類別標題,在$ taxonomy裏面我得到了'Add Package Type',這很好。但我希望將網頁與我剛剛輸入的標題名稱相同。
感謝
function custom_create_packages($term_id, $tt_id, $taxonomy){
if($taxonomy == 'package type'){
$new_page_title = $cat_title;
$new_page_content = 'This is the page content';
$new_page_template = ''; //ex. template-custom.php. Leave blank if you don't want a custom page template.
//don't change the code bellow, unless you know what you're doing
$page_check = get_page_by_title($new_page_title);
$new_page = array(
'post_type' => 'page',
'post_title' => $new_page_title,
'post_content' => $new_page_content,
'post_status' => 'publish',
'post_author' => 1,
);
if(!isset($page_check->ID)){
$new_page_id = wp_insert_post($new_page);
if(!empty($new_page_template)){
update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
}
}
}
}
add_action('create_term', 'custom_create_packages', 10, 3);