I’ve been wasting hours and hours trying to solve a permalink issue with custom post types. It keeps returning page not found (404). When I use the default permalinks, it works, but when I switch to post-name, it breaks. I have tried changing the slug name, flush rewrite, disabling all plug-ins, a ‘custom post type permalink’ plug-in all to no gain.
Anyone have similar issues? I’m on the latest 4.0.1 version of WordPress and here is my code from functions.php:
function authors_post_type() {
$labels = array(
'name' => _x('Authors', 'post type general name'),
'singular_name' => _x('Author', 'post type singular name'),
'add_new' => _x('Add New', 'author'),
'add_new_item' => __('Add New Author'),
'edit_item' => __('Edit Author'),
'new_item' => __('New Author'),
'all_items' => __('All Authors'),
'view_item' => __('View Author'),
'search_items' => __('Search Authors'),
'not_found' => __('No authors found'),
'menu_name' => __('Authors')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'menu_position' => 5,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'authors' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' )
);
register_post_type('authors', $args);
}
add_action('init', 'authors_post_type');
3 s
Every time while you create new post type with code (plugins do that automatically) you have to rebuild/update you permalink on Settings – Permalink.