19

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

我声明了 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')
        )
    );
}
4

11 回答 11

44

这种情况似乎不太一样,但是没有在左侧管理菜单中显示的一个原因是帖子类型的名称长度超过 20 个字符 功能参考/注册帖子类型

于 2014-09-25T03:04:13.943 回答
9

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

'capability_type' => 'post'

此行进入 post 类型定义的$args数组中。

于 2016-01-12T16:23:47.370 回答
3

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

'menu_position' => 21

于 2016-07-25T12:02:10.450 回答
3

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

于 2016-10-19T07:09:30.153 回答
2

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

于 2013-07-04T05:07:18.063 回答
1

在您的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
        )
    );
}

在此处输入图像描述

于 2013-07-04T06:05:09.727 回答
1

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

于 2017-08-24T14:19:19.923 回答
1

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

'show_ui' => true,
'show_in_menu' => true,
于 2018-07-03T17:19:01.907 回答
1

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

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

于 2019-08-29T00:54:18.580 回答
0

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

它在 register_post_type( 'arteducation_post_type', $args ); 时不可见

于 2021-04-06T05:20:42.753 回答
-1

Using WP-CLI this job is easy. First create the desired custom post type:

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

At end, do not forget add to functions.php file:

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
于 2019-12-08T13:22:47.747 回答