Custom Post Type Permalink Page Not Found

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');

Solutions Collecting From Web of "Custom Post Type Permalink Page Not Found"

Every time while you create new post type with code (plugins do that automatically) you have to rebuild/update you permalink on Settings – Permalink.

I checked it with create the Authors Custom post type.

I just changed the permalink structure post name to default and again default to post name.

Its working fine.

you can try it, and let me know if you have still facing this issue.

You can put the following code by @bainternet just after the register_post_type('authors', $args); line, and it will flush the rewrite rules and may be you can have a solution.

/**
*   To Activate Custom Post Type Single page
*   @see http://en.bainternet.info/2011/custom-post-type-getting-404-on-permalinks
*/
$set = get_option('post_type_rules_flased_authors');
if ($set !== true){
   flush_rewrite_rules(false);
   update_option('post_type_rules_flased_authors',true);
}