Wordpress 自定义 post 类型分层参数重定向到 404 页面

Wordpress custom post type hierarchical argument redirects to 404 page

我注意到设置 "hierarchical" => true,使我的自定义 post 类型 return 404。我需要层次结构。

还有其他办法吗?

function create_hotel_post_type()
{
  $labels = array(
    'name'                  => _x('Hotels', 'Post Type General Name', 'asdf'),
    'singular_name'         => _x('Hotel', 'Post Type Singular Name', 'asdf'),
    'menu_name'             => __('Hotels', 'asdf'),
    'name_admin_bar'        => __('Hotel', 'asdf'),
    'archives'              => __('Archives', 'asdf'),
    'parent_item_colon'     => __('Parent hotel', 'asdf'),
    'all_items'             => __('All Hotels', 'asdf'),
    'add_new_item'          => __('Add New hotel', 'asdf'),
    'add_new'               => __('Add New', 'asdf'),
    'new_item'              => __('New Hotel', 'asdf'),
    'edit_item'             => __('Edit Hotel', 'asdf'),
    'update_item'           => __('Update hotel', 'asdf'),
    'view_item'             => __('View hotel', 'asdf'),
    'search_items'          => __('Search hotel', 'asdf'),
    'not_found'             => __('Not found', 'asdf'),
    'not_found_in_trash'    => __('Not found in Trash', 'asdf'),
    'featured_image'        => __('Featured Image', 'asdf'),
    'set_featured_image'    => __('Set featured image', 'asdf'),
    'remove_featured_image' => __('Remove featured image', 'asdf'),
    'use_featured_image'    => __('Use as featured image', 'asdf'),
    'insert_into_item'      => __('Insert into hotel', 'asdf'),
    'uploaded_to_this_item' => __('Uploaded to this hotel', 'asdf'),
    'items_list'            => __('hotels list', 'asdf'),
    'items_list_navigation' => __('hotels list navigation', 'asdf'),
    'filter_items_list'     => __('Filter hotels list', 'asdf'),
  );
  $args = array(
    'labels'                => $labels,
    'public'                => true,
    'publicly_queryable'    => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'query_var'             => true,
    'capability_type'       => 'post',
    'has_archive'           => true,
    'hierarchical'          => true,
    'menu_position'         => 1,
    'supports'              => ['title', 'thumbnail', 'page-attributes'],
    'menu_icon'             => 'dashicons-building',
    'rewrite'               => ['with_front' => false,]
  );
  register_post_type('hotel', $args);
}

我通过禁用名为“Polylang Slug”的插件解决了这个问题。似乎它导致了与永久链接的冲突。

关于 Ruvees 的回答,页面在 "with_front" 键的 "true""false" 布尔值上正确打开。