WordPress CPT 层级设置为 true 它变成 404 页面

WordPress CPT hierarchical set to true it turns to 404 page

我有 Custmom Post Type 并且有一个重写 slug,在我将 hierarchical 设置为 true 之前,它工作得很好.

分层在 wp-admin 中运行良好,但当我在前端导航时,CPT 添加的项目转到 404 页面。

请注意 flush_rewrite_rules() 已集成,而且我多次尝试使用 wordpress 4.3.1 重新提交设置中的永久链接。

$arg = [
             'public' => true,
             'show_ui' => true,
             '_builtin' => false,
             '_edit_link' => 'post.php?post=%d',
             'capability_type' => 'post',
             'hierarchical' => false,
             'rewrite' => ['slug' => 'book', 'page-attributes'],
             'query_var' => 'book',
             'supports' => ['title', 'editor', 'thumbnail'],
             'menu_position' => 5,
             'menu_icon'=> 'dashicons-testimonial'
        ];

当我设置 'hierarchical' => true, 时,它进入 404 页面。

您似乎将 page-attributes 放入了错误的数组中。它属于支持,而不是重写!在下面的数组中,我将它移到了适当的位置。希望这对您有所帮助。

$arg = [
         'public' => true,
         'show_ui' => true,
         '_builtin' => false,
         '_edit_link' => 'post.php?post=%d',
         'capability_type' => 'post',
         'hierarchical' => true,
         'rewrite' => ['slug' => 'book'],
         'query_var' => 'book',
         'supports' => ['title', 'editor', 'thumbnail', 'page-attributes'],
         'menu_position' => 5,
         'menu_icon'=> 'dashicons-testimonial'
    ];