无法为新的自定义帖子类型注册分类法

时间:2018-09-03 21:38:26

标签: php wordpress

在同一安装上运行2个功能插件。其中之一注册它没有问题的自定义帖子类型和分类。但是,另一种则不注册分类法(帖子类型本身注册没有问题)。

这是第一个插件的帖子类型注册的代码(一切正常)

/* Ads Custom Post Type */
/*======================*/
function create_post_type() {
  register_post_type( 'Ads',
    array(
      'labels' => array(
        'name'               => 'Ads',
        'singular_name'      => 'Ad',
        'menu_name'          => 'Ads',
        'name_admin_bar'     => 'Ad',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Ad',
        'new_item'           => 'New Ad',
        'edit_item'          => 'Edit Ad',
        'view_item'          => 'View Ad',
        'all_items'          => 'All Ads',
        'search_items'       => 'Search Ads',
        'parent_item_colon'  => 'Parent Ads:',
        'not_found'          => 'No ads found.',
        'not_found_in_trash' => 'No ads found in Trash.'
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => true,
      'hierarchical' => true,
      'supports' => array( 
        'title', 
        'revisions'
    ),
    )
  );
  register_taxonomy("Placements", array("ads"), array(
    "hierarchical" => true,
    "label" => "Placements",
    "singular_label" => "Placement",
    "rewrite" => true
    ));
}

add_action( 'init', 'create_post_type' );

这是不注册分类法的

/* Related Custom Post Type */
/*======================*/
function create_related_post_type() {
  register_post_type( 'Related',
    array(
      'labels' => array(
        'name'               => 'Related',
        'singular_name'      => 'Related Unit',
        'menu_name'          => 'Related Units',
        'name_admin_bar'     => 'Related Unit',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Unit',
        'new_item'           => 'New Unit',
        'edit_item'          => 'Edit Unit',
        'view_item'          => 'View Unit',
        'all_items'          => 'All Units',
        'search_items'       => 'Search Units',
        'parent_item_colon'  => 'Parent Units:',
        'not_found'          => 'No units found.',
        'not_found_in_trash' => 'No units found in Trash.'
        ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => true,
      'hierarchical' => true,
      'supports' => array( 
        'title', 
        'revisions'
    ),
    )
  );
  register_taxonomy("Collection", array("Related"), array(
    "hierarchical" => true,
    "label" => "Placements",
    "singular_label" => "Placement",
    "rewrite" => true
    ));
   }

   add_action( 'init', 'create_related_post_type' );

这是我得到的错误代码。但是,不确定是否与此问题有关。可能与设置页面相关。

[2018年9月3日星期一20:09:55.199466] [proxy_fcgi:error] [pid 26021] [client 127.0.0.1:33527] AH01071:错误'PHP消息:PHP警告:call_user_func_array()期望参数1为有效的回调,函数'Related_init'或在/home/sitedomain/blabla/public_html/wp-includes/class-wp-hook.php行286 \ n'上找不到无效的函数名,引用者:sitedomain / wp-admin / edit.php?post_type = related&page =相关

1 个答案:

答案 0 :(得分:0)

来自法典:

功能register post type

register_post_type( $post_type, $args );

$post_type (string) (required):最大20个字符,不能包含大写字母或空格。

$args (array) (optional):一个参数数组。


函数register taxonomy

register_taxonomy( $taxonomy, $object_type, $args );

$taxonomy (string) (required):分类法的名称。名称应仅包含小写字母和下划线字符,且长度不能超过32个字符(数据库结构限制)。

$object_type (array/string) (required):分类对象的对象类型名称。对象类型可以是内置的帖子类型或可以注册的任何自定义帖子类型。

$args (array) (optional):一个参数数组。