php - 自定义帖子类型未显示在管理栏中
问题描述
我在 mu_plugins 文件夹中创建了自定义帖子类型。但它没有显示在管理菜单栏中。我尝试将代码粘贴到functions.php 中,但没有任何变化。我使用了 register_post_type 函数来创建新的帖子类型。请参阅下面的代码
<?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');
?>
请帮忙
解决方案
有一种更好更简单的方法来创建自定义帖子类型,您可以使用插件https://wordpress.org/plugins/custom-post-type-ui/并在创建帖子类型之后
在创建自定义帖子类型后,您可以根据需要删除插件,并且您可以获得这样的代码,只需复制此代码并在 function.php 中过去,它也可以在没有插件的情况下正常工作。
推荐阅读
- ios - 需要为 SKStoreReviewController 自定义弹出警报
- kotlin - 如何使用数组读取存储到 Firestore 的数据?
- c# - 如何在 .net 核心中使用 cert.pem、private.key 创建 pfx 文件
- laravel - Laravel api sanctum CSRF 令牌在 chorme 中不匹配
- c# - 将列表与另一个列表进行比较并获取匹配项
- node.js - npm 错误!无法确定要运行的可执行文件
- java - Json 到 POJO 空字段
- c# - 如何在不覆盖值的情况下映射列表
- symfony - Findby() 中的 Symfony LIKE 标准
- unity3d - 是否可以直接向相机显示图像?