自定义分类未显示在帖子页面上

时间:2019-07-22 作者:rmlumley

我有一个带有自定义分类法的自定义帖子类型,多年来一直运行良好,但最近我看到custom taxonomy doesn\'t show up in the individual custom post type anymore. 然而,它确实显示在列表中,我可以很好地快速编辑它。

enter image description here

我禁用了我们所有的插件和相同的问题。你知道我遗漏了什么吗?

这是我必须构建自定义帖子类型和分类的代码。

// Register Profiles
function cpt_profiles() {
    $labels = array(
        \'name\' => __( \'Profile\', \'profile\' ),
        \'singular_name\' => __( \'Profile\', \'profile\' ),
        \'add_new\' => __( \'Add Profile\', \'profile\' ),
        \'all_items\' => __( \'All Profiles\', \'profile\' ),
        \'add_new_item\' => __( \'Add New Profile\', \'profile\' ),
        \'edit_item\' => __( \'Edit Profile\', \'profile\' ),
        \'new_item\' => __( \'New Profile\', \'profile\' ),
        \'view_item\' => __( \'View Profile\', \'profile\' ),
        \'search_items\' => __( \'Search Profiles\', \'profile\' ),
        \'not_found\' => __( \'No Profiles found\', \'profile\' ),
        \'not_found_in_trash\' => __( \'No Profiles found in Trash\', \'profile\' ),
        \'parent_item_colon\' => __( \'Parent Profile:\', \'profile\' ),
        \'menu_name\' => __( \'Profiles\', \'profile\' ),
    );
    $rewrite = array(
        \'slug\'                  => \'profile\',
        \'with_front\'            => false,
        \'pages\'                 => true,
        \'feeds\'                 => true,
    );
    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => false,
        \'supports\' => array( \'title\', \'editor\', \'author\', \'revisions\', \'thumbnail\'),
        \'taxonomies\' => array( \'profile_category\'),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'show_in_rest\' => true,
        \'menu_position\' => 10,
        \'menu_icon\' => \'dashicons-universal-access\',
        \'show_in_nav_menus\' => false,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => $rewrite,
        \'capability_type\' => \'post\'
    );

    register_post_type( \'profile\', $args );
}
add_action( \'init\', \'cpt_profiles\' );

// Register Profile Areas
function tax_profile_topics() {

    $labels = array(
        \'name\'                       => _x( \'Areas\', \'Taxonomy General Name\', \'text_domain\' ),
        \'singular_name\'              => _x( \'Area\', \'Taxonomy Singular Name\', \'text_domain\' ),
        \'menu_name\'                  => __( \'Areas\', \'text_domain\' ),
        \'all_items\'                  => __( \'All Items\', \'text_domain\' ),
        \'parent_item\'                => __( \'Parent Item\', \'text_domain\' ),
        \'parent_item_colon\'          => __( \'Parent Item:\', \'text_domain\' ),
        \'new_item_name\'              => __( \'New Area\', \'text_domain\' ),
        \'add_new_item\'               => __( \'Add Area\', \'text_domain\' ),
        \'edit_item\'                  => __( \'Edit Area\', \'text_domain\' ),
        \'update_item\'                => __( \'Update Area\', \'text_domain\' ),
        \'view_item\'                  => __( \'View Area\', \'text_domain\' ),
        \'separate_items_with_commas\' => __( \'Separate items with commas\', \'text_domain\' ),
        \'add_or_remove_items\'        => __( \'Add or remove items\', \'text_domain\' ),
        \'choose_from_most_used\'      => __( \'Choose from the most used\', \'text_domain\' ),
        \'popular_items\'              => __( \'Popular Items\', \'text_domain\' ),
        \'search_items\'               => __( \'Search Items\', \'text_domain\' ),
        \'not_found\'                  => __( \'Not Found\', \'text_domain\' ),
        \'no_terms\'                   => __( \'No items\', \'text_domain\' ),
        \'items_list\'                 => __( \'Items list\', \'text_domain\' ),
        \'items_list_navigation\'      => __( \'Items list navigation\', \'text_domain\' ),
    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => false,
        \'show_tagcloud\'              => false,
    );
    register_taxonomy( \'profile_category\', array( \'profile\' ), $args );

}
add_action( \'init\', \'tax_profile_topics\');

2 个回复
最合适的回答,由SO网友:nmr 整理而成

你错过了\'show_in_rest\' => true 在里面register_taxonomy(). 默认值为FALSE, 因此,如果使用Gutenberg编辑器,您的自定义分类法将不可见。

SO网友:Joel Garcia Nuño

我想是的,那会对你有帮助的。

setup at register_taxonomy $args:

$capabilities = array (
        \'manage_terms\' => \'publish_mysuffix\', //by default only admin
        \'edit_terms\' => \'publish_mysuffix\',
        \'delete_terms\' => \'publish_mysuffix\',
        \'assign_terms\' => \'publish_mysuffix\' 
      );

changes, capatability_type property at cpt \'post\' to:

\'capability_type\' => \'mysuffix\'
那么应该是grant 这个role\'s:

$admin = get_role(\'my_role_name_may_admin\');
$admin_caps = array(
    \'read\',
    \'edit_pages\',
    \'edit_published_pages\',
    \'edit_others_pages\',
    \'publish_pages\',
    \'edit_mysuffix\',
    \'edit_others_mysuffix\',
    \'edit_private_mysuffix\',
    \'edit_published_mysuffix\',
    \'publish_mysuffix\',
    \'read_private_mysuffixs\',
    \'delete_mysuffix\',
    \'delete_others_mysuffix\',
    \'delete_private_mysuffix\',
    \'delete_published_mysuffix\'
);
foreach ($admin_caps as $cap) {
    $admin->add_cap($cap);
}
hook add\\u action(\'after\\u setup\\u theme\',\'add\\u custom\\u roles\');

相关推荐