2013-12-10 115 views
0

如何通過使用此代碼添加分類? 當我點擊新的分類,我得到一個錯誤自定義分類不工作在自定義後wordpress

function people_init() { 
    // create a new taxonomy 
    register_taxonomy(
     'people', 
     'new_post', 
     array(
      'label' => __('People'), 
      'rewrite' => array('slug' => 'person'), 
      'capabilities' => array(
       'assign_terms' => 'edit_guides', 
       'edit_terms' => 'publish_guides' 
      ) 
     ) 
    ); 
}add_action('init', 'people_init'); 

這是錯誤消息:

你不允許編輯這個項目。

回答

0

試試下面的代碼:

function people_init() { 
// create a new taxonomy 
register_taxonomy(
    'people', 
    'new_post', 
    array(
     'label' => __('People'), 
     'rewrite' => array('slug' => 'person'), 

    ) 
); 
}add_action('init', 'people_init'); 
+0

waao .. !!它的工作很好......謝謝先生。 不同的代碼有什麼問題。 – user3060132

+0

此錯誤代碼..?爲什麼.....。 '能力'=>數組( 'assign_terms'=> 'edit_guides', 'edit_terms'=> 'publish_guides' ) – user3060132

+0

因爲你已經通過錯誤的參數,就可以使用像 '能力'=>數組( ' assign_terms'=>'edit_posts', 'edit_terms'=>'manage_categories' ) –

0

這是有問題的代碼。刪除它可以讓你創建和編輯條款。

'capabilities' => array(
    'assign_terms' => 'edit_guides', 
    'edit_terms' => 'publish_guides' 
) 

能力edit_guidespublish_guides默認不存在,需要爲你所選擇的用戶可以創建你添加它之前看到的WordPress的法典add_cap()關於如何做到這一點的詳細信息。

+0

好的感謝..但能力的作用和那裏的參數 – user3060132

+0

功能設置誰可以做什麼。 WordPress有五個默認的「角色」,默認情況下所有角色都具有設置功能。在此實例中分配可選的自定義功能將允許您設置WP,以便只有特定用戶(無論他們擁有哪個「角色」)可以爲自定義分類標準創建/編輯術語。如果你沒有定義能力,那麼WP只使用默認值,所以任何擁有'Role''Editor'(或以上)的人都可以創建/編輯條款。查看Codex的[角色和功能](http://codex.wordpress.org/Roles_and_Capabilities)瞭解更多信息。 –

相關問題