2017-04-06 218 views
0

爲什麼我得到無效的文章類型WordPress的自定義帖子類型 - 無效的帖子類型?

function keyword_pages_init() { 
    $args = array(
     'label' => 'Keywords', 
     'public' => true, 
     'show_ui' => true, 
     'capability_type' => 'page', 
     'hierarchical' => false, 
     'rewrite' => array('slug' => 'keyword'), 
     'query_var' => true, 
     'menu_icon' => 'dashicons-admin-page', 
     'supports' => array(
      'title', 
      'editor', 
      'excerpt', 
      // 'trackbacks', 
      //'custom-fields', 
      //'comments', 
      'revisions', 
      'thumbnail', 
      'author', 
      'page-attributes', 
      ) 
     ); 
    register_post_type('keyword', $args); 
} 
add_action('init', 'keyword_pages_init'); 

是什麼出了問題?

但它是精細與A S關鍵字:

function keyword_pages_init() { 
    $args = array(
     'label' => 'Keywords', 
     'public' => true, 
     'show_ui' => true, 
     'capability_type' => 'page', 
     'hierarchical' => false, 
     'rewrite' => array('slug' => 'keywords'), 
     'query_var' => true, 
     'menu_icon' => 'dashicons-admin-page', 
     'supports' => array(
      'title', 
      'editor', 
      'excerpt', 
      // 'trackbacks', 
      //'custom-fields', 
      //'comments', 
      'revisions', 
      'thumbnail', 
      'author', 
      'page-attributes', 
      ) 
     ); 
    register_post_type('keywords', $args); 
} 
add_action('init', 'keyword_pages_init'); 

爲什麼?

但它適用於一個新的函數名稱!

function keyword2_pages_init() { 
    $args = array(
     'label' => 'Keywordsx', 
     'public' => true, 
     'show_ui' => true, 
     'capability_type' => 'page', 
     'hierarchical' => false, 
     'rewrite' => array('slug' => 'keyword'), 
     'query_var' => true, 
     'menu_icon' => 'dashicons-admin-page', 
     'supports' => array(
      'title', 
      'editor', 
      'excerpt', 
      // 'trackbacks', 
      //'custom-fields', 
      //'comments', 
      'revisions', 
      'thumbnail', 
      'author', 
      'page-attributes', 
      ) 
     ); 
    register_post_type('keyword', $args); 
} 
add_action('init', 'keyword2_pages_init'); 

爲什麼!!?

+0

這會改變的問題,它已經被使用過很多XD – Blackbam

回答

0

自定義帖子類型「關鍵字」很可能已經註冊。列出所有已註冊的日誌類型使用此功能:

var_dump(get_post_types());

https://codex.wordpress.org/Function_Reference/get_post_types

基本上名稱 「關鍵字」 將是法律 - 從文檔:

$ post_type(串)(必填)郵政類型。 (最多20個字符,不能 包含大寫字母或空格)默認值:無

https://codex.wordpress.org/Function_Reference/register_post_type

如果您確信蛞蝓關鍵字不用於別的東西和錯誤依然存在,它也可能是WordPress核心中的一個錯誤。如果你能找到報道它的東西。

特別是在過去有數百個WordPress項目,我也遇到過這個問題一兩次。 https://wordpress.stackexchange.com/questions/3820/deregister-custom-post-types

而且你應該: -

如果職位類型已經存在的答案如何註銷後類型可以在這裏找到(但是它可能已經被其他插件或類似的註冊是有原因的)注意add_action也有一個參數$priority。優先級可能很重要

https://developer.wordpress.org/reference/functions/add_action/

+0

。我如何重置? – laukok

+1

那麼如果一些插件或主題的其他部分使用這個關鍵字,你可能不應該刪除它,否則該插件將不再工作了;-) 無論如何,這是你如何註銷後類型:http:// wordpress.stackexchange.com/questions/3820/deregister-custom-post-types – Blackbam

0

register_post_type('keyword',$ args);

我覺得關鍵字已按主題或關鍵字儲備使用,你可以和前綴像pre_keyword

如果不工作,改變塞得改變這種

它會解決我認爲的問題。我沒有測試它,因爲我不在這裏測試。

相關問題