Php 自定义帖子类型未显示在管理栏中

Php 自定义帖子类型未显示在管理栏中,php,wordpress,Php,Wordpress,我在mu_plugins文件夹中创建了自定义帖子类型。但是它没有显示在管理菜单栏中。 我尝试在functions.php中粘贴代码,但没有改变。 我已经使用register\u post\u type函数创建了新的post类型。 请参阅下面的代码 <?php function odays_post_types() { register_post_type('hotels', array( 'capability_type' => 'hotels', 'map_m

我在mu_plugins文件夹中创建了自定义帖子类型。但是它没有显示在管理菜单栏中。 我尝试在functions.php中粘贴代码,但没有改变。 我已经使用register\u post\u type函数创建了新的post类型。 请参阅下面的代码

 <?php
function odays_post_types()
{
  register_post_type('hotels', array(
    'capability_type' => 'hotels',
    'map_meta_cap' => true,
    'rewrite' => array('slug' => 'hotels'),
    'show_in_rest' => true,
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
    'has_archive' => true,
    'public' => false,
    'show_ui' => true,
    'labels' => array(
      'name' => 'Hotels',
      'add_new_item' => 'Add New Hotel',
      'edit_item' => 'Edit Hotel',
      'all_items' => 'All Hotels',
      'singular_name' => 'Hotel'
    ),
    'menu_icon' => 'dashicons-admin-multisite'
  ));
  register_post_type('clinic', array(
    'capability_type' => 'clinic',
    'map_meta_cap' => true,
    'rewrite' => array('slug' => 'clinic'),
    'show_in_rest' => true,
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
    'public' => true,
    'labels' => array(
      'name' => 'Clinics',
      'add_new_item' => 'Create New Clinic',
      'edit_item' => 'Edit Clinic',
      'all_items' => 'All Clinics',
      'singular_name' => 'Clinic'
    ),
    'menu_icon' => 'dashicons-plus-alt'
  ));
  register_post_type('agent', array(
    'capability_type' => 'agent',
    'map_meta_cap' => true,
    'rewrite' => array('slug' => 'agent'),
    'show_in_rest' => true,
    'public' => true,
    'labels' => array(
      'name' => 'Agents',
      'add_new_item' => 'Create New Agent',
      'edit_item' => 'Edit Agent',
      'all_items' => 'All Agents',
      'singular_name' => 'Agent'
    ),
    'menu_icon' => 'dashicons-plus-alt'
  ));
}
add_action('init', 'odays_post_types');
 ?>


请帮助

您可以将此代码复制并粘贴到functions.php文件中

//注册定制邮政式诊所 函数create_clinic_cpt(){


你只需要删除

'capability_type' => 'hotels',
'capability_type' => 'clinic',
'capability_type' => 'agent',

有一种创建自定义帖子类型的更好更简单的方法,您可以在创建帖子类型后使用插件


创建自定义帖子类型后,如果需要,您可以删除插件,也可以获得类似这样的代码。只需复制此代码并在function.php中通过。没有插件也可以正常工作。

我已经很久没有使用WP了。您不必安装插件以使其出现在菜单中吗?检查mu插件加载到en的顺序确保init钩子尚未启动。如果启动了,您可以尝试“在主题设置之后”。请确认那里的代码正在运行。根据此处的图表(),我的评论不正确(mu插件早于init)。这可能是另一个奇怪的计时问题。此外,请确保show_ui参数默认为true,否则,请将其设置为true。当我删除这些参数时,后台会发生什么情况?
'capability_type' => 'hotels',
'capability_type' => 'clinic',
'capability_type' => 'agent',