Wordpress 自定义帖子类型未显示在管理左侧边栏菜单中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17051263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:16:01  来源:igfitidea点击:

Wordpress Custom Post Types doesn't show in admin left sidebar menu

wordpresscustom-post-type

提问by user2475614

I have a weird problem with one of my custom post type that doesn't show in left sidebar admin menu.

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

I declared 5 custom post types but the fifth doesn't show in left menu. Here it's the Clients post type that doesn't show. I made a lot of search about this, without success.

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

Thanks a lot for your help !

非常感谢你的帮助 !

    /**
 * 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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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')
        )
    );
}

回答by Tihomir Mihaylov

This case does not seem to be the same, but one reason for not showing in the left admin menu is the length of the name of the post type is longer than 20 characters Function Reference/register post type

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

回答by Nik

In my case I was able to see the custom post type in the left side bar as administrator but the authors could not. What I had to change was the capability_typefrom pageto postsince that's what authors are enabled to by default.

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

'capability_type' => 'post'

This line goes in the in the $argsarray of the definition of the post type.

此行位于帖子类型定义的$args数组中。

回答by Picard

if you use User Role Editor plugin it is sometimes needed to add ("Users" -> "User Role Editor" -> "Add Capability") some custom capabilities like: 'read', 'edit_post', 'delete_post', 'read_post' by hand to be able (to have rights) to see your custom post

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

回答by Willster

Sometimes this can be caused by the menu_positionclashing with another menu position, or perhaps being hidden away by some other plugin. Try changing that value.

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

'menu_position' => 21

'menu_position' => 21

回答by Tepken Vannkorn

Add 'show_in_menu' => true,after 'public' => true,

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

回答by ravi patel

Add code on your function.php.

在您的function.php.

See the below defined image:

请参阅以下定义的图像:

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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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' => __('Vtheitroad 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
        )
    );
}

enter image description here

在此处输入图片说明

回答by Stefan

I just had the same issue, and nothing helps for me. But I found a solution (temporally), I go to Appearance > Customizeand there it was, Custom post typewas there. I don't know what causes this bug because in localhost everything was fine, but on live, it's not working.

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

回答by Gavin

You may have just set the required attributes to false. These attributes must be set to truein order for the custom post type to show in the WordPress admin menu on the left:

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

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

回答by wp-overwatch.com

If this is only happening on one specific user account, but it's working on all others, then you'll need to have the user that this is happening to do the following:

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

From the menus page, go to "screen options" in the top right corner, and then check and uncheck your custom post type. This refreshes something internally, and fixes the problem. If upon clicking "screen options", you don't see your custom post type listed, then you need to use one of the other solutions posted here.

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

回答by Bruno Wego

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

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

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

At end, do not forget add to functions.phpfile:

最后,不要忘记添加到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