亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自定義帖子類型未顯示在管理欄中

自定義帖子類型未顯示在管理欄中

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它也可以在沒有插件的情況下正常工作。

http://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 關注
  • 102 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號