我注意到设置"hierarchical" => true
,使我的自定义帖子类型返回404
。我需要层次。
还有别的办法吗?
-
我尝试通过settings-> permallinks来刷新我的永久链接,但它不起作用。
-
我也尝试了flush_rewrite_rules(),但它也不起作用。
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"
布尔值都能正常打开页面。