更漂亮的解决方案是禁用创建自定义\\u post\\u类型的功能:
只需传递参数\'create_posts\' => \'do_not_allow\',
调用时在功能阵列中register_post_type
.
$args = array(
\'label\' => __( \'Custom Post Type\', \'text_domain\' ),
\'description\' => __( \'Custom Post Type\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'map_meta_cap\' => true,
\'capabilities\' => array(
\'create_posts\' => \'do_not_allow\'
)
);
register_post_type( \'custom_post_type\', $args );