为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
森林海 2022-09-17 17:54:07
我已经在mu_plugins文件夹中创建了自定义帖子类型。但它没有显示在管理菜单栏中。我尝试将代码粘贴到函数中.php,但没有更改。我使用register_post_type函数来创建新的帖子类型。请参阅下面的代码 <?phpfunction 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'); ?>
查看完整描述

3 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

有一种更好,更简单的方法来创建自定义帖子类型,您可以在创建帖子类型 https://wordpress.org/plugins/custom-post-type-ui/ 和使用插件

创建自定义帖子类型后,您可以根据需要删除插件,并且可以获取这样的代码,只需复制此代码并在函数中过去.php它也可以在没有插件的情况下正常工作。

//img1.sycdn.imooc.com//632599790001435a16040586.jpg

查看完整回答
反对 回复 2022-09-17
?
GCT1015

TA贡献1827条经验 获得超4个赞

您只需要删除


'capability_type' => 'hotels',

'capability_type' => 'clinic',

'capability_type' => 'agent',


查看完整回答
反对 回复 2022-09-17
?
一只甜甜圈

TA贡献1836条经验 获得超5个赞

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


注册自定义邮政类型诊所功能 create_clinic_cpt() {


$labels = array(

    'name' => _x( 'clinic', 'Post Type General Name', 'textdomain' ),

    'singular_name' => _x( 'clinic', 'Post Type Singular Name', 'textdomain' ),

    'menu_name' => _x( 'clinic', 'Admin Menu text', 'textdomain' ),

    'name_admin_bar' => _x( 'clinic', 'Add New on Toolbar', 'textdomain' ),

    'archives' => __( 'clinic Archives', 'textdomain' ),

    'attributes' => __( 'clinic Attributes', 'textdomain' ),

    'parent_item_colon' => __( 'Parent clinic:', 'textdomain' ),

    'all_items' => __( 'All clinic', 'textdomain' ),

    'add_new_item' => __( 'Add New clinic', 'textdomain' ),

    'add_new' => __( 'Add New', 'textdomain' ),

    'new_item' => __( 'New clinic', 'textdomain' ),

    'edit_item' => __( 'Edit clinic', 'textdomain' ),

    'update_item' => __( 'Update clinic', 'textdomain' ),

    'view_item' => __( 'View clinic', 'textdomain' ),

    'view_items' => __( 'View clinic', 'textdomain' ),

    'search_items' => __( 'Search clinic', 'textdomain' ),

    'not_found' => __( 'Not found', 'textdomain' ),

    'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),

    'featured_image' => __( 'Featured Image', 'textdomain' ),

    'set_featured_image' => __( 'Set featured image', 'textdomain' ),

    'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),

    'use_featured_image' => __( 'Use as featured image', 'textdomain' ),

    'insert_into_item' => __( 'Insert into clinic', 'textdomain' ),

    'uploaded_to_this_item' => __( 'Uploaded to this clinic', 'textdomain' ),

    'items_list' => __( 'clinic list', 'textdomain' ),

    'items_list_navigation' => __( 'clinic list navigation', 'textdomain' ),

    'filter_items_list' => __( 'Filter clinic list', 'textdomain' ),

);

$args = array(

    'label' => __( 'clinic', 'textdomain' ),

    'description' => __( '', 'textdomain' ),

    'labels' => $labels,

    'menu_icon' => '',

    'supports' => array(),

    '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' => false,

    'exclude_from_search' => false,

    'show_in_rest' => true,

    'publicly_queryable' => true,

    'capability_type' => 'post',

);

register_post_type( 'clinic', $args );


  }

 add_action( 'init', 'create_clinic_cpt', 0 );


查看完整回答
反对 回复 2022-09-17
  • 3 回答
  • 0 关注
  • 124 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号