I have noticed that setting "hierarchical" => true
, makes my custom post types return 404
. I need hierarchy.
Is there any other way around?
I tried flushing my permalinks by going to settings->permalinks, but it didn't work.
I also tried flush_rewrite_rules() but it didn't work either.
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);
}
CodePudding user response:
It has nothing to do with hierarchical
argument.
You just needed to remove 'rewrite'=>['with_front' => false,]
argument.
Let me know if you could get it to work.
And the child page:
CodePudding user response:
I fixed the issue by disabling a plugin called "Polylang Slug". Seems like it was causing conflict with permalinks.
As to Ruvees answer, page opens up properly on both
"true"
and"false"
boolean values of the"with_front"
key.