I know it’s common problem.
First i want say – I try: flush rewrite, reset Permalink Settings, Delete .htacces
and create again using Permalink Settings, tried: flush_rewrite_rules()
.
Problem: Custom post_type show 404 when using Permalink Settings – /%postname%/, without work fine, same problem is with build in posts!.
When I create one post_type – it work, but when create next one – work only last post type added, first one post_type give 404.
Here is my Create post function:
add_action( 'init', 'create_post_types', 0 );
function create_post_types() {
/***********************************
*
* Register post type - Svømming
*
***********************************/
$labels = array(
'name' => _x( 'Svømming', 'Post Type General Name', TD),
'singular_name' => _x( 'Svømming', 'Post Type Singular Name', TD ),
'menu_name' => __( 'Svømming', TD ),
'name_admin_bar' => __( 'Svømming', TD ),
);
$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes');
$args = array(
'label' => __( 'Svømming', TD ),
'description' => __( 'Svømming', TD ),
'labels' => $labels,
'supports' => $supports,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => THEMEURL.'/img/swimming2x2.svg',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => '/' ),
'capability_type' => 'page',
);
register_post_type( 'svomming', $args );
/***********************************
*
* Register post type - Stup
*
***********************************/
$labels = array(
'name' => _x( 'Stup', 'Post Type General Name', TD),
'singular_name' => _x( 'Stup', 'Post Type Singular Name', TD ),
'menu_name' => __( 'Stup', TD ),
'name_admin_bar' => __( 'Stup', TD ),
);
$supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes');
$args = array(
'label' => __( 'Stup', TD ),
'description' => __( 'Stup', TD ),
'labels' => $labels,
'supports' => $supports,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => THEMEURL.'/img/stup.svg',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => '/' ),
'capability_type' => 'page',
);
register_post_type( 'stup', $args );
/* There will be 4 more post types */
}
Those Post types must be hierarchical, and slug => ‘/’
I have totally no idea why there is that problem 🙁
The strangest part is – why work only last registered post type and why build in “posts” don’t work
The problem is that you are creating two post types having the same slug. You should change the slug in one of the.
You can’t have two post types with same slug, so change name of one of them, don’t forget to update your permalinks: Go to Settings-> Permalinks and click Save changes button in the bottom without changing any of the settings, this will simply update the permalinks table. And this will do it..
Use different post name. The post type you created will not be deleted from the database. So create new post type with some other name. Select the Permalink Settings to Post name