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

我已经在mu_plugins文件夹中创建了自定义帖子类型。但它没有显示在管理菜单栏中。我尝试将代码粘贴到函数中.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');

 ?>


森林海
浏览 127回答 3
3回答

偶然的你

有一种更好,更简单的方法来创建自定义帖子类型,您可以在创建帖子类型&nbsp;https://wordpress.org/plugins/custom-post-type-ui/&nbsp;和使用插件创建自定义帖子类型后,您可以根据需要删除插件,并且可以获取这样的代码,只需复制此代码并在函数中过去.php它也可以在没有插件的情况下正常工作。

GCT1015

您只需要删除'capability_type' => 'hotels','capability_type' => 'clinic','capability_type' => 'agent',

一只甜甜圈

您可以将此代码复制并粘贴到函数.php文件中。注册自定义邮政类型诊所功能 create_clinic_cpt() {$labels = array(&nbsp; &nbsp; 'name' => _x( 'clinic', 'Post Type General Name', 'textdomain' ),&nbsp; &nbsp; 'singular_name' => _x( 'clinic', 'Post Type Singular Name', 'textdomain' ),&nbsp; &nbsp; 'menu_name' => _x( 'clinic', 'Admin Menu text', 'textdomain' ),&nbsp; &nbsp; 'name_admin_bar' => _x( 'clinic', 'Add New on Toolbar', 'textdomain' ),&nbsp; &nbsp; 'archives' => __( 'clinic Archives', 'textdomain' ),&nbsp; &nbsp; 'attributes' => __( 'clinic Attributes', 'textdomain' ),&nbsp; &nbsp; 'parent_item_colon' => __( 'Parent clinic:', 'textdomain' ),&nbsp; &nbsp; 'all_items' => __( 'All clinic', 'textdomain' ),&nbsp; &nbsp; 'add_new_item' => __( 'Add New clinic', 'textdomain' ),&nbsp; &nbsp; 'add_new' => __( 'Add New', 'textdomain' ),&nbsp; &nbsp; 'new_item' => __( 'New clinic', 'textdomain' ),&nbsp; &nbsp; 'edit_item' => __( 'Edit clinic', 'textdomain' ),&nbsp; &nbsp; 'update_item' => __( 'Update clinic', 'textdomain' ),&nbsp; &nbsp; 'view_item' => __( 'View clinic', 'textdomain' ),&nbsp; &nbsp; 'view_items' => __( 'View clinic', 'textdomain' ),&nbsp; &nbsp; 'search_items' => __( 'Search clinic', 'textdomain' ),&nbsp; &nbsp; 'not_found' => __( 'Not found', 'textdomain' ),&nbsp; &nbsp; 'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),&nbsp; &nbsp; 'featured_image' => __( 'Featured Image', 'textdomain' ),&nbsp; &nbsp; 'set_featured_image' => __( 'Set featured image', 'textdomain' ),&nbsp; &nbsp; 'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),&nbsp; &nbsp; 'use_featured_image' => __( 'Use as featured image', 'textdomain' ),&nbsp; &nbsp; 'insert_into_item' => __( 'Insert into clinic', 'textdomain' ),&nbsp; &nbsp; 'uploaded_to_this_item' => __( 'Uploaded to this clinic', 'textdomain' ),&nbsp; &nbsp; 'items_list' => __( 'clinic list', 'textdomain' ),&nbsp; &nbsp; 'items_list_navigation' => __( 'clinic list navigation', 'textdomain' ),&nbsp; &nbsp; 'filter_items_list' => __( 'Filter clinic list', 'textdomain' ),);$args = array(&nbsp; &nbsp; 'label' => __( 'clinic', 'textdomain' ),&nbsp; &nbsp; 'description' => __( '', 'textdomain' ),&nbsp; &nbsp; 'labels' => $labels,&nbsp; &nbsp; 'menu_icon' => '',&nbsp; &nbsp; 'supports' => array(),&nbsp; &nbsp; 'taxonomies' => array(),&nbsp; &nbsp; 'public' => true,&nbsp; &nbsp; 'show_ui' => true,&nbsp; &nbsp; 'show_in_menu' => true,&nbsp; &nbsp; 'menu_position' => 5,&nbsp; &nbsp; 'show_in_admin_bar' => true,&nbsp; &nbsp; 'show_in_nav_menus' => true,&nbsp; &nbsp; 'can_export' => true,&nbsp; &nbsp; 'has_archive' => true,&nbsp; &nbsp; 'hierarchical' => false,&nbsp; &nbsp; 'exclude_from_search' => false,&nbsp; &nbsp; 'show_in_rest' => true,&nbsp; &nbsp; 'publicly_queryable' => true,&nbsp; &nbsp; 'capability_type' => 'post',);register_post_type( 'clinic', $args );&nbsp; }&nbsp;add_action( 'init', 'create_clinic_cpt', 0 );
打开App,查看更多内容
随时随地看视频慕课网APP