从我第一眼看到的情况来看,您缺少一个报价:
\'name\' => \'Events,
应为:
\'name\' => \'Events\',
此外,据我所知,您对自定义帖子类型的声明是不完整的(格式非常难看)。
尝试以下操作:
<?php
/* Register Custom Post Type \'events\' */
function prefix_register_custom_post_type(){
// Custom Post Type Name
$cpt_name = \'events\';
// CPT Features/possible values:
// \'title\', \'editor\', \'comments\', \'revisions\', \'trackbacks\', \'author\', \'excerpt\', \'page-attributes\', \'thumbnail\', \'custom-fields\', and \'post-formats\'
$cpt_features = array(
\'title\',
\'revisions\',
\'thumbnail\',
\'editor\'
);
// Slug
$cpt_slug = \'events\'; // What the URL will look like
$labels = array(
\'name\' => __(\'Events\', \'text-domain\'),
\'singular_name\' => __(\'Event\', \'text-domain\'),
\'menu_name\' => __(\'Events\', \'text-domain\'),
\'name_admin_bar\' => __(\'Events\', \'text-domain\'),
\'all_items\' => __(\'All events\', \'text-domain\'), // Archive Page Name
\'add_name\' => __(\'Add new event\', \'text-domain\'),
\'add_new_item\' => __(\'Add new event\', \'text-domain\'),
\'edit\' => __(\'edit event\', \'text-domain\'),
\'edit_item\' => __(\'edit event\', \'text-domain\'),
\'new_item\' => __(\'New event\', \'text-domain\'),
\'view\' => __(\'View event\', \'text-domain\'),
\'view_item\' => __(\'View event\', \'text-domain\'),
\'search_items\' => __(\'Search \', \'text-domain\'),
\'parent\' => __(\'Parent\', \'text-domain\'),
\'not_found\' => __(\'No events found\', \'text-domain\'),
\'not_found_in_trash\' => __(\'No events found in Trash\', \'text-domain\')
);
/* ------------------------------------------ End of Edit */
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 21,
\'menu_icon\' => \'dashicons-awards\',
\'can_export\' => true,
\'delete_with_user\' => false,
\'hierarchical\' => true,
\'has_archive\' => true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'map_meta_cap\' => true,
// \'capabilities\' => array(),
\'rewrite\' => array(
\'slug\' => $cpt_slug,
\'with_front\'=> true,
\'pages\' => true,
\'feeds\' => false
),
\'supports\' => $cpt_features
);
register_post_type($cpt_name, $args);
}
add_action(\'init\', \'prefix_register_custom_post_type\');
由于此格式更易于阅读,请检查或将代码替换为此格式,然后重试。此代码通常允许“编辑器”访问和操作已注册的自定义帖子类型。另请参阅已注释的“功能”数组,您可以在其中输入“edit\\u posts”之类的内容。