Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在wordpress中输入自定义帖子类型_Php_Wordpress_Custom Post Type - Fatal编程技术网

Php 无法在wordpress中输入自定义帖子类型

Php 无法在wordpress中输入自定义帖子类型,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我的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',

我的
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版本或主题可能有问题

您使用的是哪个wordpress版本? 因为它在wordpress 4.5.0和4.5.1中工作得非常好。
所以,更新你的wordpress或激活另一个主题并尝试。您的wordpress版本或主题可能有问题

我发现你的密码有错误。在
'taxonomies'=>数组('category','post_tag')中替换
。仍然相同。它不会创建自定义帖子type@Sieanghay,我可以看出脚本中没有任何问题。我已经在WordPress4.5.1上进行了测试,运行良好。代码中没有问题。激活另一个主题并放入代码。我发现代码中有错误。在
'taxonomies'=>数组('category','post_tag')中替换
。仍然相同。它不会创建自定义帖子type@Sieanghay,我可以看出脚本中没有任何问题。我已经在WordPress4.5.1上进行了测试,运行良好。代码中没有问题。激活另一个主题并放置代码。