在同一安装上运行 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' );
这是我得到的错误代码。不过不确定,是否与此问题有关。可能与设置页面相关。
[周一 9 月 03 日 20:09:55.199466 2018] [proxy_fcgi:错误] [PID 26021] [客户端 127.0.0.1:33527] AH01071:收到错误"PHP 消息:PHP 警告:call_user_func_array(( 期望参数 1 是有效的回调,找不到函数"Related_init"或/home/sitedomain/blabla/public_html/wp-include/class-wp-.php hook 中的函数名称无效',引用:sitedomain/wp-admin/edit.php?post_type=related&page=Related
来自 codex:
功能寄存器柱型
register_post_type( $post_type, $args );
$post_type (string) (required)
:最多 20 个字符,不能包含大写字母或空格。
$args (array) (optional)
:参数数组。
函数寄存器分类
register_taxonomy( $taxonomy, $object_type, $args );
$taxonomy (string) (required)
:分类的名称。名称应仅包含小写字母和下划线字符,并且长度不应超过 32 个字符(数据库结构限制(。
$object_type (array/string) (required)
:分类对象的对象类型的名称。对象类型可以是内置的帖子类型或任何可以注册的自定义帖子类型。
$args (array) (optional)
:参数数组。