【问题标题】:Wordpress Custom Post Types doesn't show in admin left sidebar menuWordpress 自定义帖子类型未显示在管理员左侧边栏菜单中
【发布时间】:2013-06-11 18:32:59
【问题描述】:

我的一个自定义帖子类型有一个奇怪的问题,它没有显示在左侧边栏管理菜单中。

我声明了 5 种自定义帖子类型,但第 5 种未显示在左侧菜单中。这是未显示的客户帖子类型。我对此进行了很多搜索,但没有成功。

非常感谢您的帮助!

    /**
 * Custom Posts Types
 */

add_action('init', 'create_team_post_type');
function create_team_post_type() {
    register_post_type( 'phil_team',
        array(
            'labels' => array(
                'name' => __('Équipe'),
                'singular_name' => __('Individu'),
                'add_new' => __('Ajouter'),
                'add_new_item' => __('Ajouter un individu'),
                'view_item' => __('Voir individu'),
                'edit_item' => __('Modifier individu'),
                'search_items' => __('Rechercher un individu'),
                'not_found' => __('Individu non trouvé'),
                'not_found_in_trash' => __('Individu non trouvé dans la corbeille')
            ),
            'public' => true,
            'hierarchical' => false,
            'menu_position' => 21,
            'rewrite' => array('slug' => 'team'),
            'supports' => array('title', 'editor', 'thumbnail'),
            'show_ui' => true
        )
    );
}

add_action('init', 'create_projects_post_type');
function create_projects_post_type() {
    register_post_type( 'phil_projects',
        array(
            'labels' => array(
                'name' => __('Projets'),
                'singular_name' => __('Projet'),
                'add_new' => __('Ajouter'),
                'add_new_item' => __('Ajouter un projet'),
                'view_item' => __('Voir projet'),
                'edit_item' => __('Modifier projet'),
                'search_items' => __('Rechercher un projet'),
                'not_found' => __('Projet non trouvé'),
                'not_found_in_trash' => __('Projet non trouvé dans la corbeille')
            ),
            'public' => true,
            'menu_position' => 21,
            'query_var' => 'project',
            'rewrite' => array('slug' => 'who-we-help/our-work'),
            'supports' => array('title', 'editor', 'thumbnail'),
            'show_ui' => true
        )
    );

    $set = get_option('post_type_rules_flased_POST-TYPE-NAME-HERE');
    if ($set !== true){
       flush_rewrite_rules(false);
       update_option('post_type_rules_flased_POST-TYPE-NAME-HERE',true);
}
}

add_action('init', 'create_slideshow_post_type');
function create_slideshow_post_type() {
    register_post_type( 'phil_home_slideshow',
        array(
            'labels' => array(
                'name' => __('Slideshow'),
                'singular_name' => __('Image'),
                'add_new' => __('Ajouter'),
                'add_new_item' => __('Ajouter une image'),
                'view_item' => __('Voir image'),
                'edit_item' => __('Modifier image'),
                'search_items' => __('Rechercher une image'),
                'not_found' => __('Image non trouvé'),
                'not_found_in_trash' => __('Image non trouvé dans la corbeille')
            ),
            'public' => true,
            'hierarchical' => false,
            'menu_position' => 21,
            'rewrite' => array('slug' => 'slideshow'),
            'supports' => array('title', 'editor', 'thumbnail'),
            'show_ui' => true
        )
    );
}

add_action('init', 'create_home_boxes_post_type');
function create_home_boxes_post_type() {
    register_post_type( 'phil_home_boxes',
        array(
            'labels' => array(
                'name' => __('Boîtes page d\'accueil'),
                'singular_name' => __('Boîte'),
                'add_new' => __('Ajouter'),
                'add_new_item' => __('Ajouter une boîte'),
                'view_item' => __('Voir boîte'),
                'edit_item' => __('Modifier boîte'),
                'search_items' => __('Rechercher une boîte'),
                'not_found' => __('Boîte non trouvé'),
                'not_found_in_trash' => __('Boîte non trouvé dans la corbeille')
            ),
            'public' => true,
            'hierarchical' => false,
            'menu_position' => 21,
            'supports' => array('title', 'editor', 'thumbnail'),
            'show_ui' => true
        )
    );
}

add_action('init', 'create_clients_post_type');
function create_clients_post_type() {
    register_post_type( 'phil_clients',
        array(
            'labels' => array(
                'name' => __('Clients'),
                'singular_name' => __('Client'),
                'add_new' => __('Ajouter'),
                'add_new_item' => __('Ajouter un client'),
                'view_item' => __('Voir client'),
                'edit_item' => __('Modifier client'),
                'search_items' => __('Rechercher une client'),
                'not_found' => __('Client non trouvé'),
                'not_found_in_trash' => __('Client non trouvé dans la corbeille')
            ),
            'public' => true,
            'show_ui' => true,
            'hierarchical' => false,
            'menu_position' => 21,
            'supports' => array('title', 'editor', 'thumbnail')
        )
    );
}

【问题讨论】:

    标签: wordpress custom-post-type


    【解决方案1】:

    这种情况似乎不太一样,但是左侧管理菜单中没有显示的一个原因是帖子类型的名称长度超过 20 个字符 Function Reference/register post type

    【讨论】:

    • 这是我的情况。谢谢你。多么疯狂的限制 - 20 就像什么都没有!
    • 谢谢你。 Wordpress 没有告诉我这是问题所在。
    • 谢谢!这也是我的问题。
    • 你救了我的命...谢谢。
    【解决方案2】:

    在我的情况下,我能够以管理员身份在左侧栏中看到自定义帖子类型,但作者不能。 我必须更改的是 page 到 post 的 capability_type,因为这是默认情况下启用的作者。

    'capability_type' => 'post'
    

    这一行进入文章类型定义的 $args 数组中。

    【讨论】:

    • 谢谢。这就是我的问题。它已设置为自定义值并更改为“发布”解决了问题。
    【解决方案3】:

    有时这可能是由于menu_position 与另一个菜单位置发生冲突,或者可能被其他一些插件隐藏了。尝试更改该值。

    'menu_position' => 21

    【讨论】:

    • 旁注:这只是旧 WP 版本中的问题。
    • 在 4.9.10 中这对我来说仍然是个问题
    【解决方案4】:

    您可能刚刚将所需的属性设置为 false。这些属性必须设置为true,以便自定义帖子类型显示在左侧的 WordPress 管理菜单中:

    'show_ui' => true,
    'show_in_menu' => true,
    

    【讨论】:

      【解决方案5】:

      如果这只发生在一个特定的用户帐户上,但它适用于所有其他帐户,那么您需要让发生这种情况的用户执行以下操作:

      从菜单页面,转到右上角的“屏幕选项”,然后选中和取消选中您的自定义帖子类型。这会在内部刷新某些内容,并解决问题。如果单击“屏幕选项”后,您没有看到列出的自定义帖子类型,那么您需要使用此处发布的其他解决方案之一。

      【讨论】:

      • 我自己也是这样。
      【解决方案6】:

      如果您使用用户角色编辑器插件,有时需要添加(“用户”->“用户角色编辑器”->“添加功能”)一些自定义功能,例如:'read'、'edit_post'、'delete_post' , 'read_post' 手动 'read_post' 以便能够(有权)查看您的自定义帖子

      【讨论】:

      • 这是我的解决办法。谢谢!
      【解决方案7】:

      在'public' => true, 之后添加'show_in_menu' => true,

      【讨论】:

        【解决方案8】:

        我也遇到了同样的问题,但对我没有任何帮助。但是我找到了一个解决方案(暂时),我去了Appearance > Customize,它就在那里,Custom post type 就在那里。我不知道是什么导致了这个错误,因为在 localhost 中一切都很好,但在现场,它不起作用。

        【讨论】:

          【解决方案9】:

          在您的 function.php 上添加代码。

          参见下面定义的图像:

          add_action('init', 'create_team_post_type');
          function create_team_post_type() {
              register_post_type( 'phil_team',
                  array(
                      'labels' => array(
                          'name' => __('Équipe'),
                          'singular_name' => __('Individu'),
                          'add_new' => __('Ajouter'),
                          'add_new_item' => __('Ajouter un individu'),
                          'view_item' => __('Voir individu'),
                          'edit_item' => __('Modifier individu'),
                          'search_items' => __('Rechercher un individu'),
                          'not_found' => __('Individu non trouvé'),
                          'not_found_in_trash' => __('Individu non trouvé dans la corbeille')
                      ),
                      'public' => true,
                      'has_archive' => true,
                      'hierarchical' => false,
                      'menu_position' => 21,
                      'rewrite' => array('slug' => 'team'),
                      'supports' => array('title', 'editor', 'thumbnail'),
                      'show_ui' => true
                  )
              );
          }
          
          add_action('init', 'create_projects_post_type');
          function create_projects_post_type() {
              register_post_type( 'phil_projects',
                  array(
                      'labels' => array(
                          'name' => __('Projets'),
                          'singular_name' => __('Projet'),
                          'add_new' => __('Ajouter'),
                          'add_new_item' => __('Ajouter un projet'),
                          'view_item' => __('Voir projet'),
                          'edit_item' => __('Modifier projet'),
                          'search_items' => __('Rechercher un projet'),
                          'not_found' => __('Projet non trouvé'),
                          'not_found_in_trash' => __('Projet non trouvé dans la corbeille')
                      ),
                      'public' => true,
                      'has_archive' => true,
                      'menu_position' => 21,
                      'query_var' => 'project',
                      'rewrite' => array('slug' => 'who-we-help/our-work'),
                      'supports' => array('title', 'editor', 'thumbnail'),
                      'show_ui' => true
                  )
              );
          
              $set = get_option('post_type_rules_flased_POST-TYPE-NAME-HERE');
              if ($set !== true){
                 flush_rewrite_rules(false);
                 update_option('post_type_rules_flased_POST-TYPE-NAME-HERE',true);
          }
          }
          
          add_action('init', 'create_slideshow_post_type');
          function create_slideshow_post_type() {
              register_post_type( 'phil_home_slideshow',
                  array(
                      'labels' => array(
                          'name' => __('Slideshow'),
                          'singular_name' => __('Image'),
                          'add_new' => __('Ajouter'),
                          'add_new_item' => __('Ajouter une image'),
                          'view_item' => __('Voir image'),
                          'edit_item' => __('Modifier image'),
                          'search_items' => __('Rechercher une image'),
                          'not_found' => __('Image non trouvé'),
                          'not_found_in_trash' => __('Image non trouvé dans la corbeille')
                      ),
                      'public' => true,
                      'has_archive' => true,
                      'hierarchical' => false,
                      'menu_position' => 21,
                      'rewrite' => array('slug' => 'slideshow'),
                      'supports' => array('title', 'editor', 'thumbnail'),
                      'show_ui' => true
                  )
              );
          }
          
          add_action('init', 'create_home_boxes_post_type');
          function create_home_boxes_post_type() {
              register_post_type( 'phil_home_boxes',
                  array(
                      'labels' => array(
                          'name' => __('Boîtes page d\'accueil'),
                          'singular_name' => __('Boîte'),
                          'add_new' => __('Ajouter'),
                          'add_new_item' => __('Ajouter une boîte'),
                          'view_item' => __('Voir boîte'),
                          'edit_item' => __('Modifier boîte'),
                          'search_items' => __('Rechercher une boîte'),
                          'not_found' => __('Boîte non trouvé'),
                          'not_found_in_trash' => __('Boîte non trouvé dans la corbeille')
                      ),
                      'public' => true,
                      'has_archive' => true,
                      'hierarchical' => false,
                      'menu_position' => 21,
                      'supports' => array('title', 'editor', 'thumbnail'),
                      'show_ui' => true
                  )
              );
          }
          
          add_action('init', 'create_clients_post_type');
          function create_clients_post_type() {
              register_post_type( 'phil_clients',
                  array(
                      'labels' => array(
                          'name' => __('Clients'),
                          'singular_name' => __('Client'),
                          'add_new' => __('Ajouter'),
                          'add_new_item' => __('Ajouter un client'),
                          'view_item' => __('Voir client'),
                          'edit_item' => __('Modifier client'),
                          'search_items' => __('Rechercher une client'),
                          'not_found' => __('Client non trouvé'),
                          'not_found_in_trash' => __('Client non trouvé dans la corbeille')
                      ),
                      'public' => true,
                      'has_archive' => true,
                      'hierarchical' => false,
                      'menu_position' => 21,
                      'supports' => array('title', 'editor', 'thumbnail'),
                      'show_ui' => true
                  )
              );
          }
          

          【讨论】:

          • 如果你没有在你的function.php中添加直接代码,你也可以在添加代码xxx.php中使用文件并在你的function.php中定义
          【解决方案10】:

          使用WP-CLI 这个工作很简单。首先创建所需的自定义帖子类型:

          wp scaffold post-type team-member \
            --label='Team Member' \
            --dashicon='id-alt' \
            --theme
          

          最后别忘了添加到functions.php文件:

          cat << EOF | tee -a $(wp eval 'echo get_theme_file_path("functions.php") . "\n";')
          
          /**
          * Custom Post Types.
          */
          require get_template_directory() . '/post-types/team-member.php';
          
          EOF
          

          【讨论】:

            【解决方案11】:

            您的自定义帖子类型名称仅接受 20 个字符, 请参见下面的示例,现在它显示在左侧的管理面板中 register_post_type('artedu_post_type', $args);

            它是不可见的 register_post_type('arteducation_post_type', $args);

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-09-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2020-11-11
              • 1970-01-01
              相关资源
              最近更新 更多