我的左侧边栏管理菜单中没有显示我自定义帖子类型之一的奇怪问题。
我声明了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')
)
);
}
答案 0 :(得分:29)
这种情况似乎不一样,但是在左侧管理菜单中没有显示的一个原因是帖子类型的名称长度超过20个字符 Function Reference/register post type
答案 1 :(得分:3)
在我的情况下,我能够在左侧栏中看到自定义帖子类型作为管理员,但作者不能。 我必须更改的是 capability_type 从页面到发布,因为这是作者默认启用的内容。
'capability_type' => 'post'
此行位于帖子类型定义的 $ args 数组中。
答案 2 :(得分:3)
如果您使用用户角色编辑器插件,有时需要添加(“用户” - >“用户角色编辑器” - >“添加功能”)一些自定义功能,例如:'read','edit_post',' delete_post','read_post'手动能够(拥有权利)查看自定义帖子
答案 3 :(得分:2)
在'show_in_menu' => true,
'public' => true,
答案 4 :(得分: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
)
);
}
答案 5 :(得分:1)
我遇到了同样的问题,对我没有任何帮助。但是我找到了一个解决方案(暂时),我转到Appearance > Customize
,就在那里,Custom post type
就在那里。我不知道导致这个错误的原因是因为在localhost中一切都很好,但是在现场,它没有用。
答案 6 :(得分:0)
有时这可能是由于menu_position
与另一个菜单位置发生冲突造成的,或者可能是被其他一些插件隐藏起来造成的。尝试更改该值。
'menu_position' => 21
答案 7 :(得分:0)
您可能刚刚将必需的属性设置为false。为了将自定义帖子类型显示在左侧的WordPress管理菜单中,必须将这些属性设置为true
:
'show_ui' => true,
'show_in_menu' => true,
答案 8 :(得分:0)
如果仅在一个特定的用户帐户上发生这种情况,而在其他所有帐户上都发生这种情况,那么您需要让用户知道这正在发生,请执行以下操作:
从菜单页面,转到右上角的“屏幕选项”,然后选中并取消选中您的自定义帖子类型。这会在内部刷新某些内容,并解决问题。如果单击“屏幕选项”后,您没有看到列出的自定义帖子类型,则需要使用此处发布的其他解决方案之一。
答案 9 :(得分:0)
使用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
答案 10 :(得分:0)
您的自定义帖子类型名称仅接受 20 个字符, 见下面的例子,现在它显示在左侧的管理面板中 register_post_type('artedu_post_type', $args);
当时是看不到的 register_post_type('arteducation_post_type', $args);