所以这里有一个奇怪的。我有自定义分类法,它们显示在与之关联的两种帖子类型的管理菜单上,但只有一种帖子类型在其编辑菜单中显示它们。(位于后期编辑屏幕的一侧,显示类别、标签和特色图片。)
Wordpress的全新安装。我有2个自定义分类法,“我有2个自定义分类法”;“格式”;和;地区;。我有两种帖子类型,”“;“事件”;和;资源;。
每个都设置为使用内置类别和一个或两个自定义分类法。它们都是由相同的函数生成的。
分类法和帖子正确关联-都在管理菜单和事件快速编辑中可见,只有一个用于资源-并且两个的主列元框都正确显示并存储其值。“我可以手动”;标签(&Q);在快速编辑中按预期进行。
但自定义分类法仅可在其中一个的编辑后GUI中进行选择。事件同时显示自定义分类法和内置类别,资源仅显示内置类别。
下面是注册分类的代码:
function rdcfp_register_custom_taxonomy ($name, $singular_name, $hierarchical, $associated_types) {
$labels = array(
\'name\' => $name,
\'singular_name\' => $singular_name,
\'add_new_item\' => \'Add New \' . $singular_name,
\'edit_item\' => \'Edit \' . $singular_name,
\'view\' => \'View\',
\'view_item\' => \'View\' . $singular_name ,
\'search_items\' => \'Search \' . $name,
\'menu_name\' => $name
);
$args = array(
\'label\' => $name,
\'labels\' => $labels,
\'show_ui\' => true,
\'public\' => true,
\'hierarchical\' => $hierarchical,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => $name ),
);
register_taxonomy($name, $associated_types, $args);
}
function rdcfp_register_region_taxonomy(){
rdcfp_register_custom_taxonomy (\'Regions\', \'Region\', false, array(\'events\'));
}
function rdcfp_register_format_taxonomy(){
rdcfp_register_custom_taxonomy (\'Formats\', \'Format\', false, array(\'events\', \'resources\'));
}
以下是注册帖子类型的代码:
function rdcfp_create_custom_post_type($name, $singular_name, $description, $hierarchical, $taxonomies, $supports, $menu_icon) {
$labels = array(
\'name\' => $name,
\'singular_name\' => $singular_name,
\'add_new_item\' => \'Add New \' . $singular_name,
\'edit_item\' => \'Edit \' . $singular_name,
\'view\' => \'View\',
\'view_item\' => \'View\' . $singular_name ,
\'search_items\' => \'Search \' . $name,
\'not_found\' => \'No \' . $name . \' found\' ,
\'not_found_in_trash\' => \'No \' . $name . \' found in trash\'
);
$args = array(
\'label\' => $name,
\'labels\' => $labels,
\'public\' => true,
\'hierarchical\' => $hierarchical,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
\'show_in_rest\' => true,
\'description\' => $description,
\'supports\' => $supports,
\'taxonomies\' => $taxonomies,
\'menu_icon\' => $menu_icon
);
register_post_type ($name, $args);
}
function rdcfp_create_events_post_type (){
$name = \'Events\';
$singular_name = \'Event\';
$description = \'A custom post type for Sales events.\';
$hierarchical = false;
$taxonomies = array(\'formats\',\'regions\', \'category\');
$supports = array(\'title\', \'featured-image\', \'thumbnail\', \'excerpt\');
$menu_icon = \'dashicons-calendar-alt\';
rdcfp_create_custom_post_type($name, $singular_name, $description, $hierarchical, $taxonomies, $supports, $menu_icon);
}
function rdcfp_create_resources_post_type (){
$name = \'Resources\';
$singular_name = \'Resource\';
$description = \'A custom post type for consideration-stage content.\';
$hierarchical = false;
$taxonomies = array(\'formats\',\'category\');
$supports = array(\'title\', \'editor\',\'featured-image\', \'thumbnail\', \'excerpt\');
$menu_icon = \'dashicons-visibility\';
rdcfp_create_custom_post_type($name, $singular_name, $description, $hierarchical, $taxonomies, $supports, $menu_icon);
}
两者都有自定义的元框,但这些字段都按预期显示和存储值。
最后是行动,以防我在那里出错:
add_action(\'init\', \'rdcfp_create_events_post_type\');
add_action(\'init\', \'rdcfp_create_resources_post_type\');
add_action(\'init\', \'rdcfp_register_region_taxonomy\', 0);
add_action(\'init\', \'rdcfp_register_format_taxonomy\', 0);
当这种奇怪的事情发生时,我通常可以在某处发现一种类型或放弃的论点,但我被难住了。有什么提示吗?