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

问题描述 投票:-1回答:1

在同一安装上运行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' );

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

[Mon Sep 03 20:09:55.199466 2018] [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',referer:sitedomain / wp-admin / edit.php ?post_type =&相关网页=相关

php wordpress
1个回答
0
投票

来自codex:

功能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):分类对象的对象类型的名称。对象类型可以是内置的Post Type或可以注册的任何Custom Post Type。

$args (array) (optional):一系列论点。

© www.soinside.com 2019 - 2024. All rights reserved.