CPT现在正在工作。我不知道为什么它会起作用,但它确实起作用了,下面是我如何让它开始起作用的。我看到了@hawkidoki的“答案”以及他如何不使用变量,所以我重新格式化了我的,使其看起来相同(如下),然后运行它,直到我注释掉它才起作用map_meta_cap:
<?php
function image_post_type(){
register_post_type(\'image_post\', array(
\'labels\' => array(
\'name\' => \'Images\',
\'singlular_name\' => \'Image\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Image\',
\'edit_item\' => \'Edit Image\',
\'new_item\' => \'New Image\',
\'all_items\' => \'All Images\',
\'view_item\' => \'View Image\',
\'search_items\' => \'Search Images\',
\'not_found\' => \'No Images found\',
\'not_found_in_trash\'=> \'No Images found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Images\'
),
\'public\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 1,
//\'menu_icon\' => \'icon32\',
\'capability_type\' => \'post\',
//\'map_meta_cap\' => false,
\'hierarchical\' => false,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'custom-fields\'),
\'register_meta_box_cb\' => \'add_meta_box_callback\',
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true
)
);
}
add_action(\'init\', \'image_post_type\');
function add_meta_box_callback(){
add_meta_box(\'image_variations\', \'Image Variations\', \'image_variations_callback\', \'image_post\', \'side\', \'low\');
}
function image_variations_callback(){
}
function add_image_post_type_to_query($query){
if(is_home() && $query->is_main_query()){
$query->set( \'post_type\', array(\'post\', \'page\', \'image_post\') );
}
return $query;
}
?>
看到这一点,我再次返回到我的旧代码和未注释的map\\u meta\\u cap,以获得相同的“您不允许”消息。在再次对其进行评论时,虽然它运行良好,但我的最终工作代码是:
<?php
function image_post_type(){
$labels = array(
\'name\' => \'Images\',
\'singlular_name\' => \'Image\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Image\',
\'edit_item\' => \'Edit Image\',
\'new_item\' => \'New Image\',
\'all_items\' => \'All Images\',
\'view_item\' => \'View Image\',
\'search_items\' => \'Search Images\',
\'not_found\' => \'No Images found\',
\'not_found_in_trash\'=> \'No Images found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Images\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 1,
//\'menu_icon\' => \'icon32\',
\'capability_type\' => \'post\',
//\'map_meta_cap\' => false,
\'hierarchical\' => false,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'custom-fields\'),
\'register_meta_box_cb\' => \'add_meta_box_callback\',
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true
);
register_post_type(\'image_post\', $args);
}
add_action(\'init\', \'image_post_type\');
function add_meta_box_callback(){
add_meta_box(\'image_variations\', \'Image Variations\', \'image_variations_callback\', \'image_post\', \'side\', \'low\');
}
function image_variations_callback(){
}
function add_image_post_type_to_query($query){
if(is_home() && $query->is_main_query()){
$query->set( \'post_type\', array(\'post\', \'page\', \'image_post\') );
}
return $query;
}
?>
Why though? 当map\\u meta\\u cap设置为false时,它怎么会导致此问题?默认值应为False。
感谢你们所有的帮助,尤其是你们@vancoder!