2017-04-06 221 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

如果不工作,改变塞得改变这种

它会解决我认为的问题。我没有测试它,因为我不在这里测试。

相关问题