2016-01-20 105 views
0

我想創建一個術語元,其中包含創建它的作者的ID,因爲我知道我需要鉤功能wp_insert_term(),但我沒有得到它WordPress的:未能掛鉤wp_insert_term

function author_as_meta($term) { 
    $x = add_term_meta(get_term_by('name', $term, 'novel'), 'owner', get_current_user_id()); 

    if(!$x) { 
     wp_die($x); 
    } 
} 
$taxonomy = 'novel'; 
add_action('create_'.$taxonomy, 'author_as_meta'); 

「小說」是我的自定義分類,我已經試過類別太多,但它仍然沒有工作,我還試圖用變量$分類應包含分類的名稱,但它會返回錯誤「未定義「

回答

0

我發現它了

function author_as_meta($term_id) { 
    add_term_meta($term_id, 'owner', get_current_user_id()); 
} 
add_action('create_novel', 'author_as_meta');