Wordpress 自定义 post 类型未出现在 wp-admin 左侧导航栏中
Wordpress custom post type not appearing in wp-admin left nav-bar
我是 WordPress 的新手,因此正在学习制作自定义插件。为此,我新注册了一个 Bluehost 账号在上面练习。由于此帐户是新帐户,因此没有安装其他插件。
按照 this 教程,我制作了一个自定义插件。该插件出现在插件选项卡中。但是当我激活它时,自定义 post 类型不会出现在 WP-admin 左侧导航栏中。然后我跟着另一个教程,但同样的事情发生了。我的 DEBUG 打开了,但没有抛出任何错误。我已经尝试了 google 上给出的所有解决方案,但没有结果。
插件文件:
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' );
谁能在这方面帮助我?
你忘了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' );
已测试并有效
我是 WordPress 的新手,因此正在学习制作自定义插件。为此,我新注册了一个 Bluehost 账号在上面练习。由于此帐户是新帐户,因此没有安装其他插件。
按照 this 教程,我制作了一个自定义插件。该插件出现在插件选项卡中。但是当我激活它时,自定义 post 类型不会出现在 WP-admin 左侧导航栏中。然后我跟着另一个教程,但同样的事情发生了。我的 DEBUG 打开了,但没有抛出任何错误。我已经尝试了 google 上给出的所有解决方案,但没有结果。
插件文件:
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' );
谁能在这方面帮助我?
你忘了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' );
已测试并有效