为什么我的自定义帖子类型没有出现在我的管理菜单中?

问题描述 投票:0回答:2

我制作了一些自定义帖子类型并且它正在工作,它们出现在我的菜单中。但现在,当我创建新的自定义帖子类型时,它没有显示在我的管理菜单中。我想提一下,在创建新的自定义帖子类型之前,我已经安装了一个插件(成员)。

    'show_in_rest' => true,
    'supports' => array('title', 'editor', 'thumbnail'),
    'public' => true,
    'labels' => array(
      'name' => 'Professors',
      'add_new_item' => 'Add New Professor',
      'edit_item' => 'Edit Professor',
      'all_items' => 'All Professors',
      'singular_name' => 'Professor'
    ),
    'menu_icon' => 'dashicons-welcome-learn-more'
  )); 

这个有效,但下一个不行

    'show_in_rest' => true,
    'supports' => array('title', 'editor'),
    'public' => false,
    'show_ui' => true,
    'labels' => array(
      'name' => 'Notes',
      'add_new_item' => 'Add New Note',
      'edit_item' => 'Edit Note',
      'all_items' => 'All Notes',
      'singular_name' => 'Note'
    ),
    'menu_icon' => 'dashicons-welcome-write-blog'
  ));

我还看到它不是在rest api中创建的

php wordpress post types
2个回答
0
投票

您可能创建了两个同名的帖子类型。请在 init hook 之后注册所有帖子类型。

function add_my_custom_post(){
  $labels = [
    'name'          => _x( 'Books', 'Post type general name', 'textdomain' ),
    'singular_name'  => _x( 'Book', 'Post type singular name', 'textdomain' ),
    'menu_name'      => _x( 'Books', 'Admin Menu text', 'textdomain' ),
  ];
  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'book' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
 );

  register_post_type( 'book', $args );
   $anotherlabels = [
    'name'          => _x( 'Pens', 'Post type general name', 'textdomain' ),
    'singular_name'  => _x( 'Pens', 'Post type singular name', 'textdomain' ),
    'menu_name'      => _x( 'Pens', 'Admin Menu text', 'textdomain' ),
  ];
 $args2 = array(
    'labels'             => $anotherlabels ,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'pen' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
 );

  register_post_type( 'pen', $args2 );
}
add_action( 'init', 'add_my_custom_post' );

0
投票

我也遇到了这个问题,并解决了它:也许我可以帮助别人解决这个问题,尽管它一点也不复杂。

我重新访问了一门课程并创建了一个与课程示例完全相同的帖子类型,但它没有显示在管理中。

该课程示例之所以有效,是因为它是在安装 Members 插件之前,并且在安装 Members 后,我们将课程的新帖子类型的权限添加到了管理员角色。

因此,我将新帖子类型的权限添加到我的管理员角色中,它就在管理员中!

因此,如果您遇到此问题,并且安装了 Members,请确保已将权限添加到管理员角色,因为这不会自动发生。

© www.soinside.com 2019 - 2024. All rights reserved.