为什么Wordpress自定义POST类型没有显示在管理面板中?

时间:2013-11-07 作者:user2421594

每次我创建自定义帖子类型时,标签永远不会显示在左侧管理面板上,但是,当您单击管理帖子类型时,标签会显示出来。。不知道发生了什么事。

4 个回复
SO网友:Oleg Butuzov

请检查show_in_menushow_ui 的参数register_post_type 在注册tham之前,请键入您的帖子。

SO网友:Mostafa islami

有时,这可能是由于menu_position 与另一个菜单位置冲突,或者可能被其他插件隐藏。尝试更改该值。

\'menu_position\' => 21

SO网友:bca tech

嗨,我有一些想法添加我也创建自定义帖子类型你需要自定义帖子类型你遵循这个代码这对我来说很有用。

// Register Custom Post Type services
function create_services_cpt() {

    $labels = array(
        \'name\' => _x( \'services\', \'Post Type General Name\', \'e-education\' ),
        \'singular_name\' => _x( \'services\', \'Post Type Singular Name\', \'e-education\' ),
        \'menu_name\' => _x( \'services\', \'Admin Menu text\', \'e-education\' ),
        \'name_admin_bar\' => _x( \'services\', \'Add New on Toolbar\', \'e-education\' ),
        \'archives\' => __( \'services Archives\', \'e-education\' ),
        \'attributes\' => __( \'services Attributes\', \'e-education\' ),
        \'parent_item_colon\' => __( \'Parent services:\', \'e-education\' ),
        \'all_items\' => __( \'All services\', \'e-education\' ),
        \'add_new_item\' => __( \'Add New services\', \'e-education\' ),
        \'add_new\' => __( \'Add New\', \'e-education\' ),
        \'new_item\' => __( \'New services\', \'e-education\' ),
        \'edit_item\' => __( \'Edit services\', \'e-education\' ),
        \'update_item\' => __( \'Update services\', \'e-education\' ),
        \'view_item\' => __( \'View services\', \'e-education\' ),
        \'view_items\' => __( \'View services\', \'e-education\' ),
        \'search_items\' => __( \'Search services\', \'e-education\' ),
        \'not_found\' => __( \'Not found\', \'e-education\' ),
        \'not_found_in_trash\' => __( \'Not found in Trash\', \'e-education\' ),
        \'featured_image\' => __( \'Featured Image\', \'e-education\' ),
        \'set_featured_image\' => __( \'Set featured image\', \'e-education\' ),
        \'remove_featured_image\' => __( \'Remove featured image\', \'e-education\' ),
        \'use_featured_image\' => __( \'Use as featured image\', \'e-education\' ),
        \'insert_into_item\' => __( \'Insert into services\', \'e-education\' ),
        \'uploaded_to_this_item\' => __( \'Uploaded to this services\', \'e-education\' ),
        \'items_list\' => __( \'services list\', \'e-education\' ),
        \'items_list_navigation\' => __( \'services list navigation\', \'e-education\' ),
        \'filter_items_list\' => __( \'Filter services list\', \'e-education\' ),
    );
    $args = array(
        \'label\' => __( \'services\', \'e-education\' ),
        \'description\' => __( \'post display theme services\', \'e-education\' ),
        \'labels\' => $labels,
        \'menu_icon\' => \'dashicons-buddicons-buddypress-logo\',
        \'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'revisions\', \'author\', \'trackbacks\', \'page-attributes\', \'post-formats\', \'custom-fields\'),
        \'taxonomies\' => array(),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'show_in_admin_bar\' => true,
        \'show_in_nav_menus\' => true,
        \'can_export\' => true,
        \'has_archive\' => true,
        \'hierarchical\' => true,
        \'exclude_from_search\' => true,
        \'show_in_rest\' => true,
        \'rest_base\' => \'true\',
        \'publicly_queryable\' => true,
        \'capability_type\' => \'post\',
    );
    register_post_type( \'services\', $args );

}
add_action( \'init\', \'create_services_cpt\', 0 );
此代码仔细使用服务=>;是我的自定义帖子类型e-education=>;是您替换并使用的我的“文本域”

SO网友:TonyG

这是一个非常古老的问题;A但我只是通过确保register_post_type 在操作“init”的回调中调用,而不是“admin\\u init”。

我在想,既然我只希望我的CPT维护对管理员可见,那么我应该在admin\\u init上进行设置。我认为正确的方法是在“init”上生成CPT仪表板菜单,为了限制可见性,请使用功能。也就是说,在CPT上设置功能,并向分配给用户的角色添加功能。看到这个了吗other SE Q&A 关于这个话题。

您不想使用is\\u admin来避免注册码。更有可能的是,应该始终为所有用户定义CPT,而我们只是想限制特定用户的可见性和维护权限(通过他们的功能)。

结束

相关推荐