我已经声明了一个自定义帖子类型,如下所示,我可以在admin中创建帖子,但当我尝试查看时,我得到了404错误。我已经使用类似的代码声明了一个以前的自定义帖子类型,它工作得很好。我不想要归档页,但想要单贴页。
我曾尝试刷新重写规则,并停用插件,但两者都不起作用。任何帮助都将不胜感激!!
//create courses post type
add_action( \'init\', \'create_courses_post_type\' );
function create_courses_post_type() {
$labels = array(
\'name\' => __( \'Courses\' ),
\'singular_name\' => __( \'Course\' ),
\'all_items\' => __( \'All Courses\' ),
\'add_new\' => _x( \'Add New Course\', \'Courses\' ),
\'add_new_item\' => __( \'Add New Course\' ),
\'edit_item\' => __( \'Edit Course\' ),
\'new_item\' => __( \'New Course\' ),
\'view_item\' => __( \'View Course\' ),
\'search_items\' => __( \'Search in Courses\' ),
\'not_found\' => __( \'No Courses found\' ),
\'not_found_in_trash\' => __( \'No Courses found in trash\' ),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => false, // Set to false hides Archive Pages
\'menu_icon\' => \'dashicons-welcome-learn-more\', //pick one here ~> https://developer.wordpress.org/resource/dashicons/
\'rewrite\' => array( \'slug\' => \'courses\' ),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'query_var\' => true,
\'menu_position\' => 9,
\'publicly_queryable\' => true
);
register_post_type( \'course\', $args );
}