【问题标题】:Wordpress custom post type not appearing in wp-admin left nav-barWordPress 自定义帖子类型未出现在 wp-admin 左侧导航栏中
【发布时间】:2021-11-25 10:00:38
【问题描述】:

我是 WordPress 新手,因此学习制作自定义插件。为此,我使用了一个新的 Bluehost 帐户来练习它。由于此帐户是新帐户,因此没有安装其他插件。

按照this 教程,我制作了一个自定义插件。该插件出现在插件选项卡中。但是当我激活它时,自定义帖子类型不会出现在 WP-admin 左侧导航栏中。然后我跟着另一个教程,但同样的事情发生了。我的调试已打开,但没有抛出任何错误。我已经尝试了谷歌给出的所有解决方案,但没有结果。

插件文件:

function tutsplus_register_post_type() {
 
    // movies
 
    $labels = array(  
        'name' => __( 'Movies' , 'tutsplus' ), 
        'singular_name' => __( 'Movie' , 'tutsplus' ), 
        'add_new' => __( 'New Movie' , 'tutsplus' ), 
        'add_new_item' => __( 'Add New Movie' , 'tutsplus' ), 
        'edit_item' => __( 'Edit Movie' , 'tutsplus' ), 
        'new_item' => __( 'New Movie' , 'tutsplus' ), 
        'view_item' => __( 'View Movie' , 'tutsplus' ), 
        'search_items' => __( 'Search Movies' , 'tutsplus' ), 
        'not_found' =>  __( 'No Movies Found' , 'tutsplus' ), 
        'not_found_in_trash' => __( 'No Movies found in Trash' , 'tutsplus' ), 
    );
 
    $args = array(
 
        'labels' => $labels, 
        'has_archive' => true, 
        'public' => true, 
        'hierarchical' => false, 
        'supports' => array( 
            'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' 
        ), 
        'rewrite'   => array( 'slug' => 'movies' ), 
        'show_in_rest' => true 
    ); 
}

add_action( 'init', 'tutsplus_register_post_type' );

有人可以在这方面帮助我吗?

【问题讨论】:

    标签: wordpress plugins


    【解决方案1】:

    你忘了register_post_type。试试下面的代码。

    function tutsplus_register_post_type() {
     
        // movies 
        $labels = array(  
            'name' => __( 'Movies' , 'tutsplus' ), 
            'singular_name' => __( 'Movie' , 'tutsplus' ), 
            'add_new' => __( 'New Movie' , 'tutsplus' ), 
            'add_new_item' => __( 'Add New Movie' , 'tutsplus' ), 
            'edit_item' => __( 'Edit Movie' , 'tutsplus' ), 
            'new_item' => __( 'New Movie' , 'tutsplus' ), 
            'view_item' => __( 'View Movie' , 'tutsplus' ), 
            'search_items' => __( 'Search Movies' , 'tutsplus' ), 
            'not_found' =>  __( 'No Movies Found' , 'tutsplus' ), 
            'not_found_in_trash' => __( 'No Movies found in Trash' , 'tutsplus' ), 
        );
     
        $args = array(
     
            'labels' => $labels, 
            'has_archive' => true, 
            'public' => true, 
            'hierarchical' => false, 
            'supports' => array( 
                'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' 
            ), 
            'rewrite'   => array( 'slug' => 'movies' ), 
            'show_in_rest' => true 
        ); 
    
        register_post_type( 'movies', $args );
        
    }
    add_action( 'init', 'tutsplus_register_post_type' );
    

    经过测试且有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2013-07-14
      相关资源
      最近更新 更多