无法在wordpress中输入自定义文章类型


Cannot input custom post type in wordpress

我的function.php:中有以下代码

function custom_post_type(){
    $labels = array(
        'name'=> 'Sports',
        'singular_name'=>'Sport',
        'add_new'=>'Add Item',
        'all_item'=>'All Item',
        'add_new_item'=>'Add Item',
        'edit_item'=>'Edit Item',
        'new_item'=>'New Item',
        'view_item'=>'View Item',
        'search_item'=>'Search Sport',
        'not_found'=>'No item found',
        'not_found_in_trash'=>'No items found in trash',
        'parent_item_colon'=>'Parent Item',
        'menu_name'=>'Sports'
    );
    $args= array(
        'labels'=>$labels,
        'public'=>true,
        'has_archive'=>true,
        'publicly_queryable'=>true,
        'query_var'=>true,
        'rewrite'=>true,
        'capability_type'=>'post',
        'hierarchical'=>false,
        'supports'=>array(
            'title',
            'editor',
            'excerpt',
            'thumbnail',
            'revisions'
        ),
        'taxonomies'=>array('category','post_tag'),
        'menu_position'=>null,
        'exclude_from_search'=>false
    );
    register_post_type('sport',$args);
}
add_action('init','custom_post_type');

这个代码正确吗?

我不知道为什么我不能在wordpress中添加自定义的帖子类型。这应该有效,但没有。

有什么地方需要我换衣服吗?

您使用的是哪个wordpress版本?因为它在wordpress 4.5.0&4.5.1。所以,更新你的wordpress或者激活另一个主题并尝试它。你的wordpress版本或主题可能有问题。