自定义帖子类型的单一视图显示主页



我创建了一个简单的帖子类型lessons

    $labels = array(
        'name'                => _x( 'Lessons', 'Post Type General Name', 'open-college' ),
        'singular_name'       => _x( 'Lesson', 'Post Type Singular Name', 'open-college' ),
        'menu_name'           => __( 'Lessons', 'open-college' ),
        'parent_item_colon'   => __( 'Parent Lesson:', 'open-college' ),
        'all_items'           => __( 'All Lessons', 'open-college' ),
        'view_item'           => __( 'View Lesson', 'open-college' ),
        'add_new_item'        => __( 'Add New Lesson', 'open-college' ),
        'add_new'             => __( 'Add New', 'open-college' ),
        'edit_item'           => __( 'Edit Lesson', 'open-college' ),
        'update_item'         => __( 'Update Lesson', 'open-college' ),
        'search_items'        => __( 'Search Lesson', 'open-college' ),
        'not_found'           => __( 'Not found', 'open-college' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'open-college' ),
    );
    $args = array(
        'label'               => __( 'lesson', 'open-college' ),
        'description'         => __( 'An Open College lesson', 'open-college' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'author', 'comments', ),
        'taxonomies'          => array( 'category' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'menu_icon'           => '',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );
    register_post_type( 'lesson', $args );

遇到的问题是,当我创建一个名为"我的示例课程"的新课程时,它说我可以在 /lesson/my-example-lesson/ 查看它,但是当我导航到该 URL 时,我只看到主页......

我尝试更新永久链接,甚至删除mod_rewrite并使用?lesson=my-example-lesson访问,但它仍然只显示主页。

single.php甚至没有被调用,它使用的是索引文件。

哎呀!我发现了问题!我为前端和后端划分了钩子,我只在后端注册自定义类型,所以当我从前端运行时,WordPress 没有找到自定义帖子类型。

最新更新