Пользовательский тип сообщения не отображается на панели администратора - PullRequest
0 голосов
/ 11 февраля 2020

Я создал пользовательские типы записей в папке 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');
 ?>

Пожалуйста, помогите

Ответы [ 3 ]

1 голос
/ 11 февраля 2020

Существует более удобный и простой способ создания настраиваемого типа записи. Вы можете использовать плагин https://wordpress.org/plugins/custom-post-type-ui/ и после создания типа записи

А после создания настраиваемого типа записи вы можете удалите плагин, если хотите, и вы можете получить код, подобный этому, просто скопируйте этот код и вставьте в функцию. php он также будет работать без плагина. enter image description here

0 голосов
/ 11 февраля 2020

Вам просто нужно удалить

'capability_type' => 'hotels',
'capability_type' => 'clinic',
'capability_type' => 'agent',
0 голосов
/ 11 февраля 2020

Вы можете скопировать и вставить этот код в свои функции. 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 );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...